From: dblack@... Date: 2006-06-23T20:34:11+09:00 Subject: Re: Class#name= Hi -- On Fri, 23 Jun 2006, Robert Dober wrote: > First let us establish what we all three seem to agree to, ty David too. > * Two references to the same object will respond identical to an identical > message. Agreed? > * It is impossible to gurantee expected behavior, I understand that rule as > "Ruby will not do something weird unless there is a good reason". > * I made one very stupid ???? above because I had already commented on the > behavior of the same object. > > What follows will not ever doubt these principles. > > If you are still with me (and if you are not please silently and politly > ignore that post, I will survive ) the key question is, and please take no > offence I will use a wording appropriate to how I feel about it. > > We have an object x, ok we create it now :) > x= mod.new > oh it has a name method, let us see > x.name => "" > great, that is a good name. > BTW I need a constant reference to that object > A = x > A.name will be "" of course I just assigned another reference to the object, > I am a clever guy, I know that pointing another reference to an object can > not possibly change the > behavior (please let us be precise here, behavior not sate, state is > internal, behavior is > what counts to the programmer) > A.name == x.name => true > > As I told you, I am sooo great > A.name => "A" > What??? You must be kidding no way. But look at x.name: irb(main):001:0> x = Module.new => # irb(main):002:0> A = x => A irb(main):003:0> x.name => "A" The assigment of the constant means that this module is henceforth identified by that constant; that's its name. So the next question is... what happens when there's another constant assignment to the same module? The module can't have multiple names, so the answer is that it retains its first name. It's like doing: S = String S.name # => the name of this class is still "String" except you're starting with an anonymous module, giving it a name (A = x), and then assigning it to a new constant. 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