Why does Ruby use respond_to? instead of responds_to?

前端 未结 2 785
礼貌的吻别
礼貌的吻别 2021-02-06 21:04

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 alwa

2条回答
  •  独厮守ぢ
    2021-02-06 21:39

    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
    

提交回复
热议问题