The difference is that "or" is a keyword rather than an operator. It
seems the Ruby parser doesn't allow it in some contexts. For example,
you cannot write
[4 or 5]
{:x => 4 or 5}
But "puts (4 or 5)" works as expected.
Anyway, I think the logical keywords aren't actually meant to be used
outside of boolean expressions. If we want to do tricks, we're probably
supposed to use the operators.
That's why there's an "||=" operator but no "or=".
The difference is that "or" is a keyword rather than an operator. It
seems the Ruby parser doesn't allow it in some contexts. For example,
you cannot write
[4 or 5]
{:x => 4 or 5}
But "puts (4 or 5)" works as expected.
That's probably parsed the same way as
puts((4 or 5))
Anyway, I think the logical keywords aren't actually meant to be used
outside of boolean expressions. If we want to do tricks, we're probably
supposed to use the operators.
That's why there's an "||=" operator but no "or=".
Anyway, I think the logical keywords aren't actually meant to be used
outside of boolean expressions. If we want to do tricks, we're probably
supposed to use the operators.
They're usually used for control flow, since they have such low precedence: