As the Object class in ruby ​​will be an instance of this subclass, the class "Class",

I understand that every class in ruby ​​is an instance of the Class class. Even for the Object class, Kernel.

However, I cannot wrap my head around the fact that the Object class, which is the ancestor of the Class class, can be an instance of the Class class, which is a subclass.

irb(main):018:0* Class.ancestors

=> [Class, Module, Object, Kernel, BasicObject]

irb(main):019:0> Object.ancestors

=> [Object, Kernel, BasicObject]

irb(main):020:0> Object.class

=> Class
+4
source share
1 answer

ancestorsthe method is under Module, and it gives list of modules included in that module. Thus, Classincludes Class, Module, Object, Kernel, BasicObjectmodules. And this is not like a subclass (does not apply to another class). Link.

0
source

All Articles