Search code examples
rubynaming-conventionsintrospection

Why does Ruby use respond_to? instead of responds_to?


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.


Solution

  • 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