Ruby, && & and, || & or
I keep encountering it in many places. So here’s a short guide about Ruby logical operators.
The essential difference between perl-ish (&& and ||) and
human-ish (and and or) versions of this operators is priority.
Quick example:
1
2true or false and false # => false
true || false && false #=> true
This happens because && has higher priority than ||, but and is
the same priority as or.
Here’s excerpt from Ruby Operator Precenedce Table listing operators from highest precedence to lowest:
&&||or,and
Also nothe that and and or have even lower priority than
assignment operators.
Know your language.