Ruby 中定义 nil 的地方
Where is defined nil in Ruby
我想知道在 Ruby MRI 编程语言中定义了 nil
对象。它看起来像一个常量,但与常量不同的是它不是大写形式。
还有一个 class 的 NilClass。但是nil
是在哪里定义的呢?谢谢
它在 keyword.rb 文件中定义:
A special "non-object". nil
is, in fact, an object (the sole instance of NilClass
), but connotes absence and indeterminacy. nil
and false
are the only two objects in Ruby that have Boolean falsehood (informally, that cause an if
condition to fail).
nil
serves as the default value for uninitialized array elements and hash values (unless the default is overridden)
来自 Ruby 官员 - Keywords and keyword_nil.
nil
是关键字,如def
、if
、class
、and
、or
、end
等。关键字在解析器中定义。
我想知道在 Ruby MRI 编程语言中定义了 nil
对象。它看起来像一个常量,但与常量不同的是它不是大写形式。
还有一个 class 的 NilClass。但是nil
是在哪里定义的呢?谢谢
它在 keyword.rb 文件中定义:
A special "non-object".
nil
is, in fact, an object (the sole instance ofNilClass
), but connotes absence and indeterminacy.nil
andfalse
are the only two objects in Ruby that have Boolean falsehood (informally, that cause anif
condition to fail).
nil
serves as the default value for uninitialized array elements and hash values (unless the default is overridden)
来自 Ruby 官员 - Keywords and keyword_nil.
nil
是关键字,如def
、if
、class
、and
、or
、end
等。关键字在解析器中定义。