From: dblack@... Date: 2006-06-23T18:59:58+09:00 Subject: Re: Class#name= Hi -- On Fri, 23 Jun 2006, Robert Dober wrote: > 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". As in most such cases, it does, instead, something that makes more sense, in light of Ruby's design, than the thing one might have expected :-) The design is such that, given this: a = obj b = a a and b are references to the same object. So: a.meth and b.meth are exactly the same thing. It's all about sending messages to objects, and in this case, you're sending the same message to the same object, and (predictably) it responds the same way both times. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) See what the readers are saying about "Ruby for Rails"! http://www.rubypowerandlight.com/quotes