有没有一种方法可以像在 Python 中那样在 Ruby 中装饰函数?也就是说,在每个函数的开头(和结尾?)执行一些操作。
像这样:http://programmingbits.pythonblogs.com/27_programmingbits/archive/50_function_decorators.html
最佳答案
如果你所说的函数是闭包,你可以使用 block :
def foo
puts 'before code'
yield
puts 'after code'
end
foo { puts 'here is the code' }
关于python - Ruby 中的函数装饰器,与 Python 中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12304168/