"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?

> I know we have it for classes (and yes: I could use a subclass instead)

That's a special case.  Consider also:

>> class Foo;end
=> nil
>> Foo
=> Foo
>> f = Foo
=> Foo
>> f.name
=> "Foo"
>> f == Foo
=> true

> but is there a way to do it with objects?

No.

> btw. why didn't matz make Class and Object be the same thing?

Err...  Because they are not the same concept.  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. :-)

irb(main):051:0* Class.class
=> Class
irb(main):052:0> Class.ancestors
=> [Class, Module, Object, Kernel]
irb(main):053:0> Object.class
=> Class
irb(main):055:0> Class.ancestors
=> [Class, Module, Object, Kernel]
irb(main):056:0> Object.ancestors
=> [Object, Kernel]

> kind greetings to all the rubyists.

Same to you.

> (btw. I like ruby very much and using it as my primary programing
language,
>  but every now and then when using it I am feeling like a child on
another
> planet. so the principal of least surprise didnt work for me at all
(every
> exploration was a big surprise, but a good one ))

Maybe you should get yourself a book about programming languages concepts
and / or about OO in special.  Just an idea.

Kind regards

    robert