在逻辑上或者布尔值得理念中,ruby的表达式中要么是真,要么是假。处理它的最佳方式是依照条件语句进行考虑如下:
1、if(class Myclass;end)
puts "Empty class definittion is true"
else
puts "Empty class definittion is false"
end
2、if(class Myclass; 1 ;end)
puts "number 1 true"
else
puts "number 1 false"
end
3、if(def m; return false ;end)
puts "methed is true"
else
puts "methed is false"
end
4、if "string"
puts "String apper to the true"
else
puts "String apper to the false"
end
5、if 100>50
puts "true"
else
puts "false"
end
输出结果
1、为假空类的定义
2、为真 非空类定义的求值结果与他所包含的最后一个值相等
3、方法为真,该方法可能会返回假,但字符串为真
4、值为真。
ruby-true/false 作为状态使用
最新推荐文章于 2022-10-23 13:10:10 发布