3
我碰到這種行爲在今天早些時候,並希望有人能夠解釋爲什麼發生這種情況:爲什麼Object類會響應在其上定義的實例方法?
class Object
def some_method
end
end
Object.respond_to?(:some_method) # => true
當然,這並不與其他類發生:
class Dog
def some_other_method
end
end
Dog.respond_to?(:some_other_method) # => false
那麼是什麼原因?
繼承鏈中的'類Object'本身就是一個'Object'。 'Object.is_a?(Object)' –
@JonathanLonowski是的,但在這種情況下也是狗。一切都是_a?(對象)。我只是困惑,爲什麼對象具體會響應其上定義的實例方法。 – loganhasson