2 ms·
Here's another fun thing in Ruby: irb(main):001:0> x = true or "hi" => true irb(main):002:0> x => true irb(main):003:0> x = false or "hi"
by gcv 16y ago
Here's another fun thing in Ruby:
irb(main):001:0> x = true or "hi"
=> true
irb(main):002:0> x
=> true
irb(main):003:0> x = false or "hi"
=> "hi"
irb(main):004:0> x
=> false
What? Short-circuit evaluation doesn't work in an assignment..? Oh.
irb(main):005:0> x = (false or "hi")
=> "hi"
irb(main):006:0> x
=> "hi"
In fairness, the || operator does not require explicit parentheses — but I still hold that operator precedence is just evil.
- brettnak 16y agoI actually was bitten by this just 2 weeks ago. It took me quite a while to figure this out.