how can Object class in ruby be an instance of it's subclass, class "Class"

101 Views Asked by At

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

However, I can not wrapper my head around how come Object class, which is an ancestor of class Class, can be an instance of class Class, which is it's 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
1

There are 1 best solutions below

0
On

ancestors method comes under Module and it gives list of modules included in that module. So, Class includes Class, Module, Object, Kernel, BasicObject modules. And its not like subclass( not extends another class). Reference.