Ruby boolean operator (or ruby parsing) bug

This has bitten me a couple times in the last few days. The Ruby “or” (or equals) operator appears to have a bug where, when used in an assignment, the first value is assigned rather than the results of the entire expression.

irb(main):001:0> x = false || true
=> true
irb(main):002:0> x
=> true
irb(main):003:0> z = false or true
=> true
irb(main):004:0> z
=> false

ruby version: ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.10.1]

I would expect z to be true in that last example.

Zemanta Pixie