Ruby 继承循环
在 Ruby 1.9.2 Core API Reference 中,它说 Object 的父级是 BasicObject。但随后它说 BasicObject 的父级是 Object。这是如何运作的?这是怎么回事?
In the 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一定是文档中的错误。从概念上讲,
BasicObject
没有父级,实际上,这通过其父级为nil
来表示。 (注意:nil
,对象,而不是NilClass
。)请注意 RubyDoc.Info,它正确显示为没有父级。
That must be a bug in the documentation. Conceptually,
BasicObject
doesn't have a parent, practically, this is represented by its parent beingnil
. (Note:nil
, the object, notNilClass
.)Note that on RubyDoc.Info, it is correctly shown as having no parent.
你说得对,Object 的父级是 BasicObject,但 BasicObject 的父级不是 Object。
You are right that Object's parent is BasicObject, but BasicObject's parent is not Object.