我想覆盖来自另一个模块B的模块A中的方法,该模块将使用猴子补丁A.
http://codepad.org/LPMCuszt
module A
def foo; puts 'A' end
end
module B
def foo; puts 'B'; super; end
end
A.module_eval { include B } # why no override ???
class C
include A
end
# must print 'A B', but only prints 'A' :(
C.new.foo
Run Code Online (Sandbox Code Playgroud)
module A
def foo
puts 'A'
end
end
module B
def foo
puts 'B'
super
end
end
include A # you need to include module A befor you can override method
A.module_eval { include B }
class C
include A
end
C.new.foo # => B A
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13017 次 |
| 最近记录: |