Let's imagine:
module A
class ClassA
def MethodA
puts "I am the original."
end
end
end
module B
module C
module D
end
end
end
Now, say you can only control what happens inside module D
(imagine your code is getting required in there), but from here you want to access or even extend module A
or class ClassA
.
If you attempt:
module A
class ClassA
def MethodA
puts "You have been overridden!"
end
end
end
...then later when A::ClassA.MethodA
is called, you'll still get "I am the original." This is because all you've really done is defined a new module called A
deep inside module D
.
How can you write code that will access/extend the true module A
at the top level, from deep inside module D
?
ClassName
orCONSTANT_NAME
.