使用基类模块中的任何方法的子类包括?
假设我有一个名为 Stream 的基类和一堆 Stream 的子类。
class Stream
include DateTimeHelper
include LinkHelper
include FormatHelper
def ...
...
end
end
class LongStream < Stream
def ...
...
end
end
因此,这里的子类可以访问包含模块中的任何方法。
例如,根据重构的历史,层次结构中的任何类都可能不使用 FormatHelper 中的任何方法。有什么方法可以让我以编程方式检查是否正在使用模块的任何方法?
Let's say I have a base class called Stream and a bunch of subclasses of Stream.
class Stream
include DateTimeHelper
include LinkHelper
include FormatHelper
def ...
...
end
end
class LongStream < Stream
def ...
...
end
end
So the subclasses here have access to whatever methods are in the include modules.
There's a chance based on history of refactoring that none of classes in the hierarchy use any methods from FormatHelper, for example. Is there any way for me to programmatically inspect whether or not any of the module's methods are being used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 alias_method 替换或增强模块的方法,以例如,在调用该模块的方法时添加日志记录。
You could replace or enhance the modules' methods using alias_method, to add logging when that module's methods are invoked, for example.