superclass
是一种方法Class
。现在NilClass
继承自Object
. 但是类Object
没有机会继承类Class
方法。
从下面看Documentaion
Classes, modules, and objects are interrelated. In the diagram that follows, the vertical arrows represent inheritance,
and the parentheses meta-classes. All metaclasses are instances of the class `Class'.
+---------+ +-...
| | |
BasicObject-----|-->(BasicObject)-------|-...
^ | ^ |
| | | |
Object---------|----->(Object)---------|-...
^ | ^ |
| | | |
+-------+ | +--------+ |
| | | | | |
| Module-|---------|--->(Module)-|-...
| ^ | | ^ |
| | | | | |
| Class-|---------|---->(Class)-|-...
| ^ | | ^ |
| +---+ | +----+
| |
obj--->OtherClass---------->(OtherClass)-----------...
是的,作为nil
的对象是正确的NilClass
,而后者又继承Object
了位于类之上的对象Class
。因此Nilclass
无法继承superclass
方法。
Object.superclass.superclass #=> nil
nil.superclass #=> undefined method error since nil is not a class