gpt4 book ai didi

ruby - 在 Ruby 中定义 nil 的地方

转载 作者:数据小太阳 更新时间:2023-10-29 08:37:19 25 4
gpt4 key购买 nike

我想知道在 Ruby MRI 编程语言中定义了 nil 对象。它看起来像一个常量,但与常量不同的是它不是大写形式。

还有 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 官方 - Keywordskeyword_nil .

关于ruby - 在 Ruby 中定义 nil 的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28628169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com