Robert Klemme wrote:

> 
> "Benny" <linux / marcrenearns.de> schrieb im Newsbeitrag
> news:2npa39F2ppenU1 / uni-berlin.de...
>> hi all,
>>
>> its time for stupid questions again :)
>>
>> is there a way to get the name of an object, e.g.
>>
>> test = MyClass.new
>> test.name #=> "test"
> 
> That's not the name of the object but the name of a variable that
> references the object.  What would you expect to be the name in this case:
> 
> test = MyClass.new
> t2   = test
> # name?
> 
ok, see my other posting:

"substitute Object#name with Object#names
in my first posting"
so it would be

test = MyClass.new
t2   = test
t2.names #=> ["t2", "test"]
test.names #=> ["t2", "test"]


>> I know we have it for classes (and yes: I could use a subclass instead)
> 
> That's a special case.  
yes I know: class names are constants

> Consider also: 
> 
>>> class Foo;end
> => nil
>>> Foo
> => Foo
>>> f = Foo
> => Foo
>>> f.name
> => "Foo"
>>> f == Foo
> => true
> 
I dont get you here :(
I think as names of classes a constants and names of variables are symbols
they are a entirely different thing (in the way ruby handles it)
I only made the statement with the subclass to get no such answer from the
list ("use a subclass if you need names"). and as I didnt want to use
constants I also didnt want to use a subclass  :)

>> but is there a way to do it with objects?
> 
> No.
from my other posting:

"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?
> 
> Err...  Because they are not the same concept.
if they behave mostly the same way in ruby
it might be reflected behind the scenes.
are the differences in the abilities of Object and
Class so big that they legitimate hard distinction in the
interpreter? or are we loosing something if Object and Class
is based on the same fundamentals apart from syntactical restrictions 
and the separated name spaces (constants vs. symbols)?

> Object is an instance of 
> Class (as Class is also, which sometimes confuses people).  Object defines
> everthing an instance is capable of (ok, together with Kernel, but that
> contains mostly methods that one uses as functions).  Could be that the
> self referenciality confused you - sometimes it's hard to grasp. :-)

I think its not confusing me on the contrary: I even vote for narrowing the
differences.


> Maybe you should get yourself a book about programming languages concepts
> and / or about OO in special.  Just an idea.
I read the whole pragmatic programmer (1st ver.) and "Programmieren mit
Ruby" /R?hrl/Schmiedl/Wyss several times and I thought it would be
sufficient. but perhaps you have a good recommendation for a pure OO book.

kind regards,

benny