From: adrfer Date: 2010-10-01T07:06:30+09:00 Subject: Re: module MyMod::MyOtherMod question The constant that classes are assigned to when defined may be prefixed by the names of existing modules using the scope operator (::). When this happens, the leading scope operator places the class or module in the top-level scope. Here is the example: CONST = 'outer' module A CONST = 'inner' end module A class B def self.get_const CONST end end end p A::B.get_const # => inner Now, class B is inserted into module A's namespace, but it's not interpreted in the context of A. As a result, the reference to CONST resolves to the top-level constant, not A's version. class A::B def self.get_const CONST end end p A::B.get_const # => outer On Sep 30, 2:12 pm, Brian Candler wrote: > Gene Angelo wrote: > > Gene Angelo wrote: > >> [I] assumed these were synonymous, but they are not: > > > I stand corrected. It appears that in order to use the following syntax: > > > module A::B > >    ... > > end > > > module A must be defined. > > Yes. But even then, > > module A; end > module A::B >   ... > end > > is different to > > module A >   module B >     ... >   end > end > > in the way that constants are looked up. > > >> module A; FOO = 123; end > => 123 > >> module A::B > >> puts FOO > >> end > > NameError: uninitialized constant A::B::FOO >   from (irb):3 >   from :0>> module A; module B > >> puts FOO > >> end; end > > 123 > => nil > -- > Posted viahttp://www.ruby-forum.com/.