Benny wrote:

> hi all,

Moin!

> is there a way to get the name of an object, e.g.
> test = MyClass.new
> test.name #=> "test"

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.

Here are some samples:

x = 5; (4 + 1).name
x = y = Object.new; x.name, y.name
Object.new.name

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

It is a bit different with classes, mainly because their names are 
constants that are available in the whole application.

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

Nope, not really.

> 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.

BTW, what are you wanting that .name method for? If it is for debugging 
reasons there might be another way of doing it.

> kind greetings to all the rubyists.
> benny

More regards,
Florian Gross