Why is Ruby using response_to? instead of replys_to?

I'm curious why the Ruby method-related validation method checks to see if the object responds to the respond_to? method respond_to? instead of responds_to?

It always seems uncomfortable to me, but perhaps because I'm used to respondsToSelector in objective-c.

+36
ruby naming-conventions introspection
Mar 12 '11 at 4:25
source share
2 answers

Matz prefers the second person singular or third person:

"responds_to?" probably makes more sense for English speakers than "Respond_to?".

May be. But I am Japanese. Ruby is not English. This is the basic naming convention to avoid the special form of third parties in standard libraries.

  you = Human.new if you.respond_to?(:knock) ... end 
+65
Mar 12 '11 at 4:40
source share

How do you know that the receiver is always the third person singular? It is possible that the receiver will be I , we , you or they , or some other thing representing plurality. In this case, you still say that responds_to? more natural than respond_to? ? To maintain generality, it is best to call the method as general as possible. Instead of calling a third-party method singular, it makes sense to call it in infinitive form by default, to infinity, which is also used in dictionaries.

+7
Mar 12 '11 at 6:11
source share



All Articles