In Rails (so, Ruby), I need either x and y to be true or just a to be true:
(x && y) || a
I suspect I could write
x && y || a
But I don't know how Ruby's precedence works. I did some testing and I still wasn't certain (especially with the anomaly on line 3):
true | true & false # => true
true || true && false # => true
true or true and false # => false #huh?
true | false & true # => true
true || false && true # => true
true or false and true # => true
Bonus points* for the difference between ||
and |
and or
(and the and
equivalents - I believe the English versions are banned in the Ruby styleguide).
But really my question is how to write (x && y) || a
without brackets.
* bonus point are only imaginary because @sawa (in the comments below) is secretly Sheldon Cooper