module B
def stub
extend()
end
def extend
puts "B:extend"
end
end
class A
include B
def extend
puts "A:extend"
end
end
a = A.new
a.stub
# output: A:extend
# would like to have: B:extend
The question is:
How to make a.stub call extend method from module B without modifying B‘s code and without renaming A‘s method extend?
include BaddsB‘s methods toAso your method definition is overwritingB‘s implementation.You could use the
aliasmethod to save a reference toB‘s method and implement your ownstubmethod inA: