From: Xavier Noria Date: 2007-11-15T05:41:21+09:00 Subject: Re: Module#constants On Nov 14, 2007, at 6:36 PM, ara.t.howard wrote: > > On Nov 14, 2007, at 5:44 AM, Xavier Noria wrote: > >> Why is M::C in scope there? > > for the same reason that File and Object are. imagine if C were > not, then we would have to write > > ::File.open path > > whenever opening a File. > > the scope crawls up the nesting. Thank you! I had once that hypothesis but this example broke it: module M C = 1 module N end end M::N.module_eval do File # -> OK C # -> NameError end File is seen but C is not. So I think there's something more into it. The best conjecture I have by now is that you need to have the enclosing module syntactically there with the nested "module/class"s. However, I have seen that even if there something syntactic the name of the constant is not used, I mean this works: module M C = 1 module N end end X = M module X module N C end end That makes some sense because if X is already a module that module is reponed, fine, but all the examples together give kind of a mix of runtime and syntatic things to take into account. I don't yet understand the complete rule. -- fxn