最好用代码解释....
>> String.ancestors
=> [String, Comparable, Object, Kernel, BasicObject]
>> Comparable.ancestors
=> [Comparable]
>> Object.ancestors
=> [Object, Kernel, BasicObject]
>> Kernel.ancestors
=> [Kernel]
>> BasicObject.ancestors
=> [BasicObject]
所以我怀疑继承链是String<对象< BasicObject ...和Comparable和Kernel是mixins ...
是否有功能' foobar'哪个可以显示继承:
>> String.foobar
=> [Object, BasicObject]
如果可能的话,还包括存储单例方法的隐藏元类?
答案 0 :(得分:6)
String.ancestors.grep(Class)
......................
答案 1 :(得分:4)
你可以这样做:
class Class
def foobar
ancestors - included_modules - [self]
end
end