Ruby为什么要使用response_to?而不是respons_to? [英] Why does Ruby use respond_to? instead of responds_to?

查看:111
本文介绍了Ruby为什么要使用response_to?而不是respons_to?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇为什么Ruby的与内省相关的检查对象是否对方法作出响应的方法是respond_to?而不是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?

在我看来总是很尴尬,但这也许是因为我习惯了Objective-c中的respondsToSelector.

It always seems awkward to me but maybe that's because I'm used to respondsToSelector in objective-c.

推荐答案

Matz 首选第二人称单数或第三人称复数:

Matz prefers second person singular or third person plural:

"responds_to?"可能会赚更多 讲英语的人比 "respond_to?".

"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

这篇关于Ruby为什么要使用response_to?而不是respons_to?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆