Ruby inheritance loop
In th开发者_高级运维e Ruby 1.9.2 Core API Reference, it says that Object's parent is BasicObject. But then it says that BasicObject's parent is Object. How does this work? What is going on here?
That must be a bug in the documentation. Conceptually, BasicObject
doesn't have a parent, practically, this is represented by its parent being nil
. (Note: nil
, the object, not NilClass
.)
Note that on RubyDoc.Info, it is correctly shown as having no parent.
You are right that Object's parent is BasicObject, but BasicObject's parent is not Object.
Object.ancestors # => [Object, Kernel, BasicObject]
BasicObject.ancestors # => [BasicObject]
精彩评论