This seems very odd to me:
module A
module B
end
end
module X
include A
module Y
B # => uninitialized constant X::Y::B (NameError
end
end
If I move the "include A" either up one line (before "module X"), or down one line (after "module Y"), then it works as expected. Since include is supposed to import all the constants from one module to the other, then surely this should make the constants of A available to anything defined within X?
My intent, in doing this, is to include A's semantics only where they are relevant...
This may or may not be the way it's supposed to work--but for me, it does violate POLS.
Puzzled,
Bob Sidebotham
Bob Sidebotham wrote:
This seems very odd to me:
module A
module B
end
end
module X
include A
module Y
B # => uninitialized constant X::Y::B (NameError
end
end
If I move the "include A" either up one line (before "module X"), or down one line (after "module Y"), then it works as expected. Since include is supposed to import all the constants from one module to the other, then surely this should make the constants of A available to anything defined within X?
My intent, in doing this, is to include A's semantics only where they are relevant...
This may or may not be the way it's supposed to work--but for me, it does violate POLS.
Puzzled,
Bob Sidebotham
You can tell ruby to start from the "root"-namespace by prefixing with a ::. See below:
module A
module B
end
end
module X
include A
module Y
::B # => uninitialized constant X::Y::B (NameError
end
end
Regards,
Brian
···
--
Brian Schröder
http://ruby.brian-schroeder.de/