From: Benny Date: 2004-08-09T22:51:18+09:00 Subject: Re: stupid question: Object#name ok after rethinking I have to correct me: substitute Object#name with Object#names in my first posting Florian Gross wrote: > No, because Objects don't have names. Variables however do. The > association between an Object to a Variable isn't really something that > is unique. ok, but AFAIK there is no variable class in ruby :) > > Here are some samples: here are some possible implementations (for Object#names) > > x = 5; x.names #=> ["x"] > (4 + 1).name #=> nil > x = y = Object.new; x.names #=> ["x","y"] y.names #=> ["x","y"] > Object.new.name #=> nil I think in the kernel we have symbols attached to object-ids (do we?) so why not have a method to show us the symbols to a corresponding object_id? > >> btw. why didn't matz make Class and Object be the same thing? > > In which context? If he did Ruby would be a prototype-based language > where the only way to build similar Objects is to have a template object > which you clone. but I thought we would have some: the class Object (since its a class its also an object in ruby) or did I get you wrong (I must admit I have no idea of the formal meaning / definition of �prototype-based language�) > > BTW, what are you wanting that .name method for? If it is for debugging > reasons there might be another way of doing it. you mean Kernel#caller, right? :) so its simply comfortable if you can use name = MyClass.new(params) instead of name = MyClass.new(name, params) the last one is doubled effort and if you accidently choose different names for the object and the content of the name-attribut you may later on have to remember 2 different names or fix it. it may also be confusing. (I like to iterate over all objects of a class and often I need the name of the object in the iteration to identify the current thing. in the iteration I like to invoke certain methods, so in the end they are processed on every object of that class) > >> kind greetings to all the rubyists. >> benny > > More regards, > Florian Gross dito, benny