responds_to?

responds_to?

The pseudo-method responds_to? determines whether a type has a method with the given name. For example:

a = 1
a.responds_to?(:abs)    #=> true
a.responds_to?(:size) #=> false

It is a pseudo-method because it only accepts a symbol literal as its argument, and is also treated specially by the compiler, as explained in if var.responds_to?(...).

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/responds_to.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部