I think Object is everyone's ancestor, including Class. So I think it should be Class.class == Object. I feel a bit of confused and twisted
+8
A:
class returns the class (#type) not the ancestor. Objects's class is Class. Class's class is Class. Class is an Object. Truth in advertising: I never learned Ruby, but the Object-Class relation has to be the one Smalltalk set forth 30 years ago.
Remus Rusanu
2009-08-02 20:08:55
Metaclasses work differently in Ruby: they get injected into the method lookup chain, thus Ruby doesn't have the two parallel hierarchies of classes and metaclasses, but, as you say, the basics are identical.
Jörg W Mittag
2009-08-03 00:38:05
@Jorg: thanks. As soon as I finish my current project I'll pick up on rails and ruby, I've hear so much praise that I'm intrigued :)
Remus Rusanu
2009-08-03 01:34:37
Thank you. I think I'm clear about the relations now. @Jörg_W_Mittag 's information helps, too. That is, classes and Metaclasses are two different but related concepts.
fwoncn
2009-08-03 03:05:04
+4
A:
This is the way it works in ruby 1.9:
Class.class = Class
Class.superclass = Module
Module.class = class
Module.superclass = Object
Object.class = Class
Object.superclass = BasicObject
BasicObject.class = Class
BasicObject.superclass = nil
ennuikiller
2009-08-02 20:15:33
+5
A:
Object
's class is Class
(since Object
itself is a class), and Object
is an ancestor of Class
.
There is a circular reference, it is pretty complex. My personal recommendation, if you don't really need to play with it, don't go there.
Sinan Taifour
2009-08-02 20:15:34