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

nil?

1
2
3
4
5
a=nil
a.nil? = true

a=""
a.nil = false

empty?

1
2
3
4
"".empty?
=> true
" ".empty?
=> false

blank?

1
2
3
4
5
6
7
8
9
10
nil.blank?
=>true
[].blank?
=> true
{}.blank?
=> true
"".blank?
=> true
"  ".blank?
=> true

present?

这个就是blank?他的反义词

1
2
3
def present?
 !blank?
end
原文地址:http://dlj.bz/rLc3ah

Comments