Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在用 ruby 做一个小项目,我想创建一个模块,我们称之为 Initializer,它修改所有混合它的类的初始化方法。这可能吗?默认情况下,类自己的 .initialize 函数会覆盖模块中的任何内容,有没有办法解决这个问题?
有几种方法可以将您的代码插入初始化过程:http ://www.ruby-doc.org/core-1.9.3/Class.html
我的建议是:不要这样做!
将元编程用于花哨的东西。