1 字符串非空判断
if str.nil? || str.empty?
xxx
else
yyy
end
2 number、数组,非空判断
if number.nil?
xxx
end
if arr.nil?
xxx
end
3 空指针异常
[logstash.inputs.mongodb ] MongoDB Input threw an exception, restarting {:exception=>#<NoMethodError: undefined method `[]' for nil:NilClass>}
logstash.inputs.mongodb:logstash/inputs/mongodb.rb 脚本报异常,
nil:NilClass 空指针异常
undefined method []' 在空对象上调用
[]’ 方法;可以推断出是某个属性为nil