From: "Hal E. Fulton" Date: 2002-07-19T16:40:15+09:00 Subject: Re: #name of instance ----- Original Message ----- From: "Tom Sawyer" To: "ruby-talk ML" Sent: Friday, July 19, 2002 2:23 AM Subject: Re: #name of instance > opps, slight typo. not bob, but bobo: > > class A > def myname > puts self.name # ? > end > end > > bobo = A.new > bobo.myname # OOPS > > producing: > > bobo Without some tremendous gyrations, it's just not possible. Remember that a variable is just a reference to an object. First of all, an object has no way of knowing what variable might reference it. Second, there could be any number of variables referencing the same object. toto = gogo = bobo = A.new toto.myname # Logically, all three gogo.myname # of these must produce bobo.myname # the same result. Thirdly, there might be no variable at all referencing the object. A.new.myname # What now? So unless you're prepared to do some weird things to associate a name with an object when it's created, there's just no way. Even if you *do* that, there are still shortcomings. Perhaps time to rethink. If you're not familiar with how Symbols work in Ruby, go look that up. That might give you some ideas. Cheers, Hal