empty? 对象的值是否为空
nil? 对象本身是否为空
rb(main):015:0> ‘‘.empty?
=> true
irb(main):016:0> ‘ ‘.empty?
=> false
irb(main):017:0> "".empty?
=> true
irb(main):018:0> " ".empty?
=> false
irb(main):019:0> nil.empty?
NoMethodError: undefined method `empty?‘ for nil:NilClass
from (irb):19
from /usr/bin/irb:12:in `<main>‘
irb(main):020:0> nil.nil?
=> true
irb(main):021:0> ‘‘.nil?
=> false
irb(main):022:0> ‘ ‘.nil?
=> false
irb(main):023:0>
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-14 12:03:04