From: Xavier Noria Date: 2012-08-08T04:15:16+09:00 Subject: Re: Nesting and constants --047d7b10cdf96262fa04c6b1cf93 Content-Type: text/plain; charset=UTF-8 On Tue, Aug 7, 2012 at 6:06 PM, Thomas Thomassen wrote: The comments there reflects what Matz mentions here: > > > http://www.justskins.com/forums/nested-class-module-namespace-42955.html#post129248 > > But I still don't understand why this is considered expected behaviour. > Well, it is expected behavior because that's the way Ruby works. A given module can be stored in a hundred constants in dozens of differently nested constant paths. Constants are largely irrelevant to Ruby, Ruby semantics are defined around module and class objects. So, the rule is that whatever module object is opened by the module keyword, that's what gets pushed to the nesting. It is simple, and it works in all cases. It does not matter the constant path used to reach the module object. Given (untested code): module M N = Module.new end module A module B C = M::N end end module M::N # (1) end module A::B::C # (2) end X = M::N module X # (3) end the nesting in (1), (2), and (3) is the same (M::N). The fact that we got the M::N module via X or A::B::C is irrelevant. And the fact that we reach it via M::N is equally irrelevant by the same principle. *Constants do not matter*, Ruby only cares about the module objects they yield. In my view all is round and follows those basic axioms, but of course the only one who can ensure which is the rationale is Matz himself. --047d7b10cdf96262fa04c6b1cf93 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Aug 7, 2012 at 6:06 PM, Thomas Thomassen <lists@ruby-forum.com<= /a>> wrote:

The comments there reflects what Matz mentions here:

http://www.justskins.com/forums/nest= ed-class-module-namespace-42955.html#post129248

But I still don't understand why this is considered expected behaviour.=

Well, it is expected behavior because = that's the way Ruby works.

A given module can = be stored in a hundred constants in dozens of differently nested constant p= aths. Constants are largely irrelevant to Ruby, Ruby semantics are defined = around module and class objects.

So, the rule is that whatever module object is opened b= y the module keyword, that's what gets pushed to the nesting. It is sim= ple, and it works in all cases. It does not matter the constant path used t= o reach the module object. Given (untested code):

=C2=A0 =C2=A0 module M
=C2=A0 =C2=A0 =C2=A0 N= =3D Module.new
=C2=A0 =C2=A0 end

= =C2=A0 =C2=A0 module A
=C2=A0 =C2=A0 =C2=A0 module B
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 C =3D M::N
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end

=C2=A0 =C2=A0 module M::N
=C2=A0 =C2=A0 =C2= =A0 # (1)
=C2=A0 =C2=A0 end

=C2=A0 =C2= =A0 module A::B::C
=C2=A0 =C2=A0 =C2=A0 # (2)
=C2=A0 = =C2=A0 end

=C2=A0 =C2=A0 X =3D M::N
=C2= =A0 =C2=A0 module X
=C2=A0 =C2=A0 =C2=A0 # (3)
=C2=A0 =C2=A0 end

<= /div>
the nesting in (1), (2), and (3) is the same (M::N). The fact tha= t we got the M::N module via X or A::B::C is irrelevant. And the fact that = we reach it via M::N is equally irrelevant by the same principle. *Constant= s do not matter*, Ruby only cares about the module objects they yield.

In my view all is round and follows those basic axioms,= but of course the only one who can ensure which is the rationale is Matz h= imself.
--047d7b10cdf96262fa04c6b1cf93--