在Ruby on Rails中对nil v。空v。空白的简要解释

一个人想着一个人 提交于 2020-08-10 05:39:17

问题:

I find myself repeatedly looking for a clear definition of the differences of nil? 我发现自己一再寻找nil?差异的明确定义nil? , blank? blank? , and empty? empty? in Ruby on Rails. 在Ruby on Rails中。 Here's the closest I've come: 这是我最接近的:

  • blank? objects are false, empty, or a whitespace string. 对象是false,空或空白字符串。 For example, "" , " " , nil , [] , and {} are blank. 例如, """ "nil[]{}为空。

  • nil? objects are instances of NilClass. 对象是NilClass的实例。

  • empty? objects are class-specific, and the definition varies from class to class. 对象是特定于类的,并且定义因类而异。 A string is empty if it has no characters, and an array is empty if it contains no items. 如果字符串没有字符,则该字符串为空;如果字符串不包含任何项目,则该字符串为空。

Is there anything missing, or a tighter comparison that can be made? 有什么遗漏,或者可以做出更严格的比较吗?


解决方案:

参考一: https://stackoom.com/question/3iKs/在Ruby-on-Rails中对nil-v-空v-空白的简要解释
参考二: https://oldbug.net/q/3iKs/A-concise-explanation-of-nil-v-empty-v-blank-in-Ruby-on-Rails
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!