ruby中的布尔逻辑’true和false == true’
> test = false and true => false > test => false > test = true and false #this is the point I don't understand! => false > test => true
为什么ruby会以这种方式运行?如何正确使用它以避免遇到此问题?
优先级。 test = true and false
表示:
(test = true) and false
不是这个:
test = (true and false)
如上所示使用括号,或者使用&&
代替and
,如果您希望分配到最后:
test = true && false