在Ruby on Rails中對nil v。空v。空白的簡要解釋 - A concise explanation of nil v. empty v. blank in Ruby on Rails

問題:

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: 這是我最接近的: spa

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

  • nil? objects are instances of NilClass. 對象是NilClass的實例。 code

  • 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? 有什麼遺漏,或者能夠作出更嚴格的比較嗎? ci


解決方案:

參考一: 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
相關文章
相關標籤/搜索