I'm curious why Ruby's introspection related method to check if an object responds to a method is respond_to?
instead of responds_to?
It always seems awkward to me but maybe that's because I'm used to respondsToSelector
in objective-c.
respond_to? is a Ruby method for detecting whether the class has a particular method on it. For example, @user.respond_to?('eat_food')
Matz prefers second person singular or third person plural:
"responds_to?" probably makes more sense to English speakers than "respond_to?".
Maybe. But I'm Japanese. Ruby is not English. It's the basic naming rule to avoid third person singular form in the standard libraries.
you = Human.new if you.respond_to?(:knock) ... end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With