在method_added中定义方法
需要 method_added
挂钩的一些帮助。
我想做的是,我有一个类和一个模块。该类扩展了模块,并且具有一些预定义的方法。在模块中,我使用 method_added
来使用 define_method
重新定义类方法。这就是基本思想:
define_singleton_method :method_added do |method|
alias :old method
define_method "#{method}" do
send "#{[some_class_method]}"
old
end
end
现在,问题是,当我使用 define_method
重新定义其中的类方法时,是否会调用 method_added
钩子?
Need a little help with the method_added
hook.
What I'm trying to do is, i have a class and a module. The class is extending the module and it has some predefined methods. In the module, I'm using method_added
to redefine the class methods using define_method
. This is what the basic idea is:
define_singleton_method :method_added do |method|
alias :old method
define_method "#{method}" do
send "#{[some_class_method]}"
old
end
end
Now, the query is, would the method_added
hook be called when i'm using define_method
to redefine the class method in there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论