示例代码:如何覆盖扩展方法?
module B
def f2
puts "B::f2"
end
end
class C
def initialize
extend B
end
def f2
puts "C::f2"
end
end
c = C.new
c.f2
上面的示例代码是我的问题的抽象。 Class C
延伸module B
在飞行(B
实际上延伸到C
的实例)。方法f2
from B
不符合我的需要,所以我想覆盖f2
。如何实现?
好,你_are_覆盖'C#有一个从'B' f2'。为什么你做这个动态扩展而不是通常的任何原因包括? –
因为在我的真实代码中,'B'是一个可配置的插件。 – TieDad