Why does Ruby use respond_to? instead of responds_to?

Nick picture Nick · Mar 12, 2011 · Viewed 11.8k times · Source

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.

Answer

Andrew Grimm picture Andrew Grimm · Mar 12, 2011

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