.nil? .empty? .blank? .present? 方法总结

Posted

###nil?

a=nil
a.nil? = true

a=""
a.nil = false

###empty?

"".empty?
=> true
" ".empty?
=> false

###blank?

nil.blank?
=>true
[].blank?
=> true
{}.blank?
=> true
"".blank?
=> true
"  ".blank?
=> true

###present? 这个就是blank?他的反义词

def present?
 !blank?
end

此文章 短链接: http://dlj.bz/1KQ46b