irb(main):013:0> Class.instance_methods
=> ["superclass", "new"]
irb(main):014:0> Class.class
=> Class
I guess Class is an object(an instance of Class?) but its of type
Class. How can an object's type be an object itself.?
The traditional response is 'magick' While it is useful to
say that all instances are Objects and Object is an instance of
class Class which itself is an Object (the class of which is Class),
at some point there has to be a limit to how deep the recursion
goes. Because ruby is implemented in C, the language design allows
this kind of 'shortcutting'.
To be productive, you sort of just have to accept this and know the
implications of Class being an Object of Class and so on. You can
don some super-chromatic peril-sensitive sunglasses if you like
In ruby, everything is an object. Even classes. Class inherits from object just like everything else (well it inherits from Module which inherits from Object). Its a little weird to get used to, but that's how it works.
···
On Jan 24, 2006, at 11:28 PM, Vivek wrote:
Hi,
can someone explain this.
irb(main):013:0> Class.instance_methods
=> ["superclass", "new"]
irb(main):014:0> Class.class
=> Class
I guess Class is an object(an instance of Class?) but its of type
Class. How can an object's type be an object itself.?
irb(main):013:0> Class.instance_methods
=> ["superclass", "new"]
irb(main):014:0> Class.class
=> Class
I guess Class is an object(an instance of Class?) but its of type
Class. How can an object's type be an object itself.?
The traditional response is 'magick' While it is useful to
say that all instances are Objects and Object is an instance of
class Class which itself is an Object (the class of which is Class),
at some point there has to be a limit to how deep the recursion
goes. Because ruby is implemented in C, the language design allows
this kind of 'shortcutting'.
To be productive, you sort of just have to accept this and know the
implications of Class being an Object of Class and so on. You can
don some super-chromatic peril-sensitive sunglasses if you like
I don't think any peril is involved (though lately all discussions
seem to lead to talking about shooting in foot, running with scissors,
etc. It's just that there's some circularity at the top of the
class/module hierarchy, for the sake of bootstrapping the whole
system.
David
--
David A. Black
dblack@wobblini.net
"Ruby for Rails", from Manning Publications, coming April 2006!
On 1/25/06, Logan Capaldo <logancapaldo@gmail.com> wrote:
In ruby, everything is an object. Even classes. Class inherits from
object just like everything else (well it inherits from Module which
inherits from Object). Its a little weird to get used to, but that's
how it works.
One implication I have seen is that the class definition itself is an
object which can be executed.This has some interesting properties.
Umm, in usual terminology objects cannot be "executed". You can "call" or
"invoke" methods but you cannot execute an object as such. You probably
meant the right thing - it just sounded quite strange...