我发现以下代码,我猜它在config/initializers/kernel.rb中。
module Kernel
private
def this_method
caller[0] =~ /`([^']*)'/ and $1
end
end
为了添加到日志中,这是获取当前方法的首选方法吗?
谢谢。
最佳答案
这似乎是获得调用方法并让您能够在代码中调用this_method
并将其添加到日志的一种不错的方法。
如果您使用的是Ruby 1.9.2,则可以改为调用__method__
,而不必担心定义一个特殊的方法。
关于ruby-on-rails - 如何在Rails 3中获取当前方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6426598/