boolean logic in ruby 'true and false == true'
问题 > test = false and true => false > test => false > test = true and false #this is the point I don't understand! => false > test => true Why does ruby behave in this way and how would I use it correctly to not run into this problem? 回答1: Precedence. test = true and false means this: (test = true) and false not this: test = (true and false) Use parentheses as above, or && instead of and , if you want the assignment to come last: test = true && false 来源: https://stackoverflow.com/questions