From: Robert Klemme Date: 2004-08-09T23:16:26+09:00 Subject: Re: stupid question: Object#name "Benny" schrieb im Newsbeitrag news:2npdjuF3728iU1@uni-berlin.de... > ok after rethinking I have to correct me: > substitute Object#name with Object#names > in my first posting No good. Benny, I seriously think you should get rid of the idea that variable identifiers are an object's names. > I think in the kernel we have symbols attached to object-ids (do we?) Nope. The association between variable names and objects is contained in the current binding (for local variables, that is). It's a different story for instance variables. >> def test; foo = Foo.new; p foo; b = binding; p( eval("foo", b)); end => nil >> test # # => nil > so why not have a method to show us the symbols to a corresponding > object_id? It's a one way street. You can only walk it in the direction of varible to instance, not the other way. It's not needed and it would be a total overhead to manage this at runtime. > >> 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�) As I said earlier, you got stuck in the self referentiality. Object is a class and class in turn is an object, too. > > 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. Of course. > (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. No, you don't need the var name for that. You can always do foo = Foo.new ObjectSpace.each_object( Foo ) do |obj| if obj.equal? foo puts "found it" else puts "other instance" end end http://www.ruby-doc.org/core/classes/Object.html#M000899 > in the iteration I like to invoke certain methods, so in the end they are > processed on every object of that class) You're making me curios why you need that and what you do. Kind regards robert