Hi people… I was watching the Dave T.’ talk on the ScotlandOnRails
2009 event about Ruby and the Object.
He say that a class does not exists on the Ruby land, a class is just an
instance of Class class.
So I was wondering, how could I define a ‘class’ without using the class
sentence … I mean:
If I do this:
class A def self.class_hello puts 'hello on class' end def instance_hello puts 'hello on instance' end end
I have a A class so I can start to instance instances of this class:
a = A.new a.instance_hello A.class_hello
But as Dave says the A class is just constant instance of Class class,
so why not try to define a constant of an instance of Class class and
try to reproduce the same behavior:
A = Class.new def A.class_hello puts 'hello on class' end a = A.new a.instance_hello # does not work A.class_hello
There it is, I could obtain the behavior of the class_hello but I
couldn’t define the instance_hello with this approx.
So my questions are:
It is possible to obtain a total behavior of a Class constant without
the ‘class’ sentence?
What is the ‘class’ sentence?, because it is not a instance_method of
‘main’ that is an instance of Object, the Object#class method returns
the name of the class of the instance but not receive any kind of
This doesn’t work:
self.class B def h puts "h" end end
Object.class B def h puts "h" end end
So, as you can see I am trying to understand things that they should be
very simple, but for the moment my brain is not ready