Why is Object.class == Class in Ruby?

I think Object is all the ancestors, including the class. Therefore, I think it should be Class.class == Object. I feel a little confused and distorted.

+5
source share
4 answers
Class

returns a class (#type), not an ancestor. The class of objects is a class. A class class is a class. A class is an object. The truth is in advertising: I never recognized Ruby, but the Object-Class relationship should be one Smalltalk set out 30 years ago.

+10
source

The class, object, module, and all other classes are instances of the class:

Class.class == Module.class == Object.class == Hash.class == Class

( ), Object, )

.superclass.superclass== ( )

. Object.class==

, , OO.

Object.class.superclass.superclass==

=> parent (.superclass)
-> instance-of (.class)

alt text http://www.grabup.com/uploads/b10b2ffa9976953e3d6f88e6fcbf6f28.png?direct

+9

Object class Class ( Object ), Object Class.

, . , , .

+6

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
+5

All Articles