"Bertram Scharpf" <lists@bertram-scharpf.de> schrieb im Newsbeitrag
news:20050128104650.GA580@homer.bertram-scharpf...
Hi,
>
> I guess that's not the same as there is some magic involved with class
> names:
>
> >> c = Class.new
> => #<Class:0x1018ab00>
> >> c.name
> => ""
> >> Foo = c
> => Foo
> >> c.name
> => "Foo"
> >> Foo.name
> => "Foo"
> >> Bar = c
> => Foo
> >> Bar.name
> => "Foo"
> >> c.name
> => "Foo"There's nothing magic. The first constant's name that the
class is assigned to will be the classes name.c=Class.new #=> #<Class:0x401e8874>
d=c #=> #<Class:0x401e8874>
e=d #=> #<Class:0x401e8874>
F=e #=> F
G=c #=> F
c.name #=> "F"
The rule and behavior is clear. The magic is that the class name
automatically is set from the identifier of the constant - normally an
object (and a class is an object) does not get to know when it is assigned
to a var/const and to which var/const it is assigned. So obviously for
const assignments there is special code that sets a class's name if the
assigned instance is a class.
Kind regards
robert
···
Am Freitag, 28. Jan 2005, 19:05:54 +0900 schrieb Robert Klemme: