问题:
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
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/4312685