开发者

Ruby inheritance loop

开发者 https://www.devze.com 2023-02-16 01:50 出处:网络
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

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]
0

精彩评论

暂无评论...
验证码 换一张
取 消