新手问题 老哥们,问个关于修改核心方法的问题

banana · 2019年01月25日 · 最后由 banana 回复于 2019年01月27日 · 1050 次阅读
module Extension
  refine AAA do
    def a
      ......
    end
  end
end

module Top
  using Extension
end

module Top::HHH
  class B
    def self.b

    end
  end
end

如上,Extension 修改了核心方法,想在 Top 模块“包含”之后,其他开发者在做类似于 Top::HHH 模块时,能够在模块的方法中可直接使用 修改后方法,该如何去做呢?

实现不了的,没办法统一添加,只能为每一个需要修改核心方法的类添加 using 语句。

Refinements 作用域只有顶级、Module 和 Class,且遇到 end 就停止了,不能用在 Method 上。

You may activate refinements at top-level, and inside classes and modules. You may not activate refinements in method scope. Refinements are activated until the end of the current class or module definition, or until the end of the current file if used at the top-level.

pinewong 回复

就没有啥好的办法可以达到这种目的吗😂

需要 登录 后方可回复, 如果你还没有账号请 注册新账号