On Thu, Feb 21, 2013 at 2:46 PM, Xavier R. [email protected] wrote:
“Class are itself objects” - this is statement is making me too
confused,when trying to feel the concept at its core.
Can anyone give me here some light?
Think of a class as a set of instructions for making something. That
something, is an object of that class. So if you declare class
Widget, and do “w = Widget.new”, w is an object of class Widget, or
for shorthand, w is a Widget.
BUT (the tricky part) a class itself is also something made using a
set of instructions. That set of instructions is the class called
Class. (You can think of that as being a set of instructions for
writing instructions, like a manual on writing manuals.) So a class
is also an object, of class Class.
To top things off, there is also a class called Object, that
everything else inherits from.
(Well, technically not any more. Now there’s BasicObject, which is
even more basic than Object. But that’s another story.)
It becomes a bit clearer when you realize you COULD do “Class.new” and
fill it in with all the various things needed to define a class. So
in that respect, Class is just another class.