ruby的逻辑运算符and与&&
ruby的逻辑运算符and与&&ruby中,and与&&是有区别的,而且不在“短路”运算上。看例子:puts true and falseputs
ruby的逻辑运算符and与&&
ruby中,and与&&是有区别的,而且不在“短路”运算上。看例子:
puts true and falseputs (true and false)puts true && falseputs true & false////~>truefalsefalsefalse
翻资料发现ruby1.8.7有这么个说法:
引用
Use &&/|| for boolean expressions, and/or for control flow. (Rule of thumb: If you have to use outer parentheses, you are using the wrong operators.)