获取和编写调用方法名称

时间:2015-07-03 09:49:44

标签: ruby-on-rails ruby

我想知道更新我的对象的方法。我有ActiveRecord类Event,其中包含method_name列。我的对象更新后,有没有办法在该列中保存调用方法?

更新

我虽然喜欢这样的事情:

class Event
  after_save :set_caller

  def set_caller
    self.update(method_name: caller)
  end
end

但此时来电者是active_support/callbacks.rb

1 个答案:

答案 0 :(得分:0)

  

问题是我不知道如何获得调用者方法名称

How to get the name of the calling method?

您可以使用

caller[0][/`.*'/][1..-2]
相关问题