在method_added中定义方法

发布于 2024-12-22 20:48:16 字数 447 浏览 2 评论 0原文

需要 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文