3 ms·
yes, that does seem pretty annoying. however, irb(main):001:0> value = false or true => true irb(main):002:0> value => false irb(main):003:0> value
by avg_dev 3y ago
yes, that does seem pretty annoying.
however,
irb(main):001:0> value = false or true
=> true
irb(main):002:0> value
=> false
irb(main):003:0> value = false || true
=> true
irb(main):004:0> value
=> true
irb(main):005:0>
I believe if you use the `||` operator instead of `or`, then things just work out fine. I agree it is really annoying. But I am pretty sure if you use a tool like RuboCop https://github.com/rubocop/rubocop https://github.com/rubocop/rubocop (a static code analysis tool) then it will catch bugs like this. Note that I am not recommending Ruby. But in my experience if I want to work with a language and it has a community style guide and a linter that enforces it, it will save me some heartache.
Just editing to add this reference: https://rubystyle.guide/#and-or-flow https://rubystyle.guide/#and-or-flow