I ran into this behavior earlier today and was hoping somebody could explain why this happens:
class Object
def some_method
end
end
Object.respond_to?(:some_method) # => true
Of course, this doesn't happen with other classes:
class Dog
def some_other_method
end
end
Dog.respond_to?(:some_other_method) # => false
So what gives?
This happens b/c
Object
is a superclass ofClass
itself. Soclass Object
is an instance ofObject
(confusing). When you define an instance method onDog
you dont cause the same issue b/c the classDog
does not appear in the inheritance chain ofClass