From: Xavier Noria Date: 2007-11-15T09:04:27+09:00 Subject: Re: Module#constants On Nov 14, 2007, at 9:41 PM, Xavier Noria wrote: > 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 Nah, that didn't add information. When the code is interpreted and we arrive to "module X" the X constant is looked up and has a module as value, which happens to be the same module object that is stored under M. So that example is no different from plain module M module N C end end This test brings some light in what I think I don't understand: module M C = 1 module N end end class Module def const_missing(c) puts self end end M::N.module_eval do C puts self end Gives: Object M::N So I think I am narrowing this to how scope works. I know module_eval sees stuff from the surrounding scope, but I think I have a misunderstanding between "scope" and "evaluating the block in the context of M::N". There's some module that's taken as a starting point to crawl up in the namespace for constant resolution (Object), and there's a different module to which method definitions _but not constant definitions_ apply (the remark about constants is not proven in the example). Can anyone define those "two" modules better? -- fxn