obj::X raises. I believe this is consistent with the feature, but maybe would deserve docs, because from the point of view of the Ruby programmer I am passing an object, no constant name resolution is happening in foo.rb. See what I mean?
I believe, from my tests, that something analogous happens if ns::C.x returns (the namespaced) Object. In the main namespace, you don't get the object passed up as-is.
I am also curious about how is this implemented (maybe to comment here, not necessarily in the docs).
Method calls somehow seem to be swapping VALUEs that correspond to builtin classes on the fly.
Please excuse I am not reading the source code to answer this myself, I do not know enough about CRuby internals to understand the patch and its implications.
Right, IOW it's the duality between builtin classes and other classes.
Builtin classes' constants, methods, ivar and cvars are all a copy per Namespace (and so potentially differ), even though for all builtin classes they are equal? with the corresponding builtin class in all namespaces.
I think that's part of what makes the semantics of Namespace complicated, but as I understand it's also part of the design of Namespace.
@Eregon (Benoit Daloze) maybe, but the fact is that you pass an object, and the callee receives a different object. This is not consistent with the current language.
Ideas:
Introduce the concept of "namespace-level root objects", documented to be swapped on the fly or something. Sounds too ad-hoc to me.
Restricting method calls to primitive types (not a good one, because their classes can still be reopened in the caller).
Disallowing cross-namespace constant access or method calls.
The last one would also fix that the design allows mixing objects from different versions of the same gem.
Implementation details aside, some conceptual solution has to be devised to make this sound.
BTW, my examples are synthetic. But for more practical minds, that Object could be an attribute three levels down the object tree from your namespace-level class instance.
The third option is more aligned with my intuitive idea of a new entity with new rules. Instead of a container of methods and constants that :: can work with, you may need a new kind of language-level entity an "isolate", a "cell", a "shield", something.