ruby中的布尔逻辑'true and false==true'

ruby中的布尔逻辑'true and false==true',ruby,boolean-logic,Ruby,Boolean Logic,为什么ruby会以这种方式运行?我如何正确地使用它来避免遇到这个问题?优先级。测试=真和假意味着: > test = false and true => false > test => false > test = true and false #this is the point I don't understand! => false > test => true 不是这个: (test = true) and false 如果希望作业

为什么ruby会以这种方式运行?我如何正确地使用它来避免遇到这个问题?

优先级。测试=真和假意味着:

> test = false and true
=> false
> test
=> false
> test = true and false #this is the point I don't understand!
=> false
> test
=> true
不是这个:

(test = true) and false  
如果希望作业排在最后,请使用上述括号或&&代替and:

test = (true and false)
优先权。测试=真和假意味着:

> test = false and true
=> false
> test
=> false
> test = true and false #this is the point I don't understand!
=> false
> test
=> true
不是这个:

(test = true) and false  
如果希望作业排在最后,请使用上述括号或&&代替and:

test = (true and false)

在github ruby样式指南中:“和或关键字被禁止。这不值得。始终使用从Perl继承的&&和| |。起初,只有&&和| |。但是,它们既像C一样被用作逻辑原语,又像shell一样被用来处理成功/失败。在后一种情况下,使用优先级导致的意外情况,比如我的@info=stat$file | | die错误在标量而不是列表上下文中调用stat。较低的优先级和/或/不被引入来解决这些难题,但给了我们新的优先级和/或不优先级,Ruby将它们与从Perl获得的其他内容一起借用了。这不值得。始终使用从Perl继承的&&和| |。起初,只有&&和| |。但是,它们既像C一样被用作逻辑原语,又像shell一样被用来处理成功/失败。在后一种情况下,使用优先级导致的意外情况,比如我的@info=stat$file | | die错误在标量而不是列表上下文中调用stat。低优先级和/或/不优先级是为了解决这些难题而引入的,但它给了我们新的优先级和/或不优先级,Ruby将这些优先级和它从Perl获得的其他内容一起借用。