From: Pete Date: 2006-06-23T21:02:17+09:00 Subject: Re: Class#name= I guess it's because constants are _constant_ so they can not be re-assigned Robert Dober schrieb: > On 6/23/06, Yukihiro Matsumoto wrote: >> >> Hi, >> >> In message "Re: Class#name=" >> on Fri, 23 Jun 2006 06:42:09 +0900, Joshua Haberman < >> joshua@reverberate.org> writes: >> >> |Is there any reason that Class#name= shouldn't exist? >> >> Modules and classes are named by the constant referencing it. If you >> want to name an anonymous module, see the following code: >> >> mod = Module.new >> NewModule = mod >> p NewModule.name # => "NewModule" >> >> matz. > > I have been inspired by this, and I found this behavior > irb > irb(main):001:0> mod = Module.new > => # > irb(main):002:0> mod.name > => "" > ok understandable > irb(main):003:0> A = mod > => A > irb(main):004:0> mod.name > => "A" > most surprising > irb(main):005:0> B = mod > => A > irb(main):006:0> mod.name > => "A" > even more surprising > irb(main):007:0> B.name > => "A" > ?????? > irb(main):008:0> > > Well this kind of shocks me, is there an idea behind this which I am > missing? > If so could you please point me there. > Sorry for being so direct, but that seems to be in violation with "Ruby > should do what you expect it to do". > > Cheers > Robert > > >