如何检索当前方法名称以便将其输出到记录器文件?

我正在使用Ruby on Rails 3.2.2,为了显示警告消息以用于开发目的,我在我的代码中使用了logger.warn 。 我想检索运行logger.warn方法名称 ,以便将该方法名称输出到日志文件中。

 class ClassName < ActiveRecord::Base def method_name # Note: This code doesn't work. It is just a sample. logger.warn "I would like to retrieve and display the #{self.class.to_s}##{method_name}" end end 

在日志文件中,我想看到:

我想检索并显示ClassName#method_name

可能吗? 如果是这样,我该怎么做?

 class ClassName < ActiveRecord::Base def method_name logger.warn "I would like to retrieve and display the #{self.class.to_s}##{__method__.to_s}" end end 

这应该做的工作。