读书人

ruby的逻辑运算符and与amp;amp

发布时间: 2013-11-30 22:36:00 作者: rapoo

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.)

读书人网 >Ruby Rails

热点推荐