nil?

nil?

The pseudo-method nil? determines whether an expression's runtime is Nil. For example:

a = 1
a.nil?          # => false

b = nil
b.nil?          # => true

It is a pseudo-method because the compiler knows about it and it can affect type information, as explained in if var-nil?(---)-

It has the same effect as writing is_a?(Nil) but it's shorter and easier to read and write-

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/nil_question.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部