我有以下如何调用类,after_create方法,无论是从规范或导轨控制台
class Item < ActiveRecord::Base
after_create TellMe
end
class TellMe
def self.after_create(model)
end
,并希望能够做这个事情类似:
i=Item.new :name => 'my test name'
i.send(:TellMe.after_create)
相似我怎么可以用公共方法打电话发送?它看起来像我可以做
i.instance_eval 'TellMe.after_create(self)'
,但感觉有点丑陋的(除其他事项外)
究竟是什么你想要做什么?你可以把它与真实代码的上下文吗? –
如果你有'after_create:tell_me',你可以有'Item.send(:tell_me)'并且在不同的上下文中使用,上面的代码非常接近实际的调用。想要以类似的方式访问此功能。 Prob一个愚蠢的问题 – timpone