简体   繁体   English

使用基本 class 模块中的任何方法的子类包括?

[英]Subclasses using any methods from base class module includes?

Let's say I have a base class called Stream and a bunch of subclasses of Stream.假设我有一个名为 Stream 的基础 class 和一堆 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.例如,根据重构历史,有可能层次结构中的所有类都没有使用来自 FormatHelper 的任何方法。 Is there any way for me to programmatically inspect whether or not any of the module's methods are being used?有什么方法可以让我以编程方式检查是否使用了任何模块的方法?

You could replace or enhance the modules' methods using alias_method , to add logging when that module's methods are invoked, for example.例如,您可以使用alias_method替换或增强模块的方法,以在调用该模块的方法时添加日志记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM