Here is what my code looks like:
module A
def foo
puts "A"
end
end
module B
include A
def bar
foo
end
end
class MyClass
include B
def foo
puts "X"
end
def self.test
puts bar
end
end
When I call “C.test” I get “X” instead of “A” (which is what I want) because the local definition of foo has overridden that in A. I can’t change the signature of either foo’s. I can only mainly edit my own class; I can edit modules A and B but lots of existing code use them and they are (so no changing foo to A.foo for instance). I am thinking of doing
class MyClass
module MyModules
include B
end
....
MyModules.bar
....
end
But this does not work.
How can I “localize” the namespace when doing include B?
I found a solution for what I wanted, might not be the best answer but works exactly the way I want it to.
This effectively allows me to limit the scope of B and all other included modules in the local class MyModules. In my code it actually has a meaning because all the included modules handle expression manipulation so I can call the local class “Expr” (and they are seriously overusing the names ‘eval’, ‘bind’ and ‘free’ right now).