Vincent Isambart wrote:
About the class name, the name of the class is not necessarily the name
of the constant that references the name. Example:
class Foo
end
Bar = Foo
Foo = 0Then you cannot do Foo.new, but Bar.name returns "Foo".
I think in fact, when the class does not exist, Ruby creates the class,
and gives it the name that is after "class". It then gives to a
constant of the same name the value of the class.If you try to add a method to Foo, it does not work :
class Foo
def a() end
end
-> TypeError: Foo is not a classYou can still add a method to the class created before :
class Bar
def a() end
endand Bar.field still returns "Foo".
So the name field of class is just a name that does not necessarily
means anything.
so if I get you right, when creating a new class three things happens:
1. creation of a new class-object
2. setting the attribute "name" of the class to the given class name
3. creation of a constance with the given class name as reference to the new
class-object
tant mieux!
then we could do the same thing everytime an object is created ( = set with
"=")!
1. creation of the object, registering its relation to its class...etc
2. setting the attribute "name" of the object to the given object name, if
not given: nil
4.name #=> nil
"test".name #=> nil
test = Test.new
test.name #=> "test"
Test.new.name #=> nil
test2 = test
test2.name #=> "test"
test2.name = "test3"
test2.name #=> "test3"
name would be just another attribut of Object just as is for Class
(and as I initially thought of)
I hope what I said was understandable ^o^
surely it was.
Regards,
Vincent Isambart
regards,
benny