07-19-2023, 12:55 AM
When I do:
puts(nil or 4)
Ruby complains:
<!-- language: lang-none -->
SyntaxError: syntax error, unexpected keyword_or, expecting ')'
Why is that? `puts(nil || 4)` does work, but I wonder why `or` doesn't. I thought the difference between the two was only in their operator precedence.
(I know the expression `nil or 4` doesn't seem useful, as it always returns `4`. It's just an example, for simplicity's sake. My actual expression is `Integer(ENV['WD'] or 4)`.)
puts(nil or 4)
Ruby complains:
<!-- language: lang-none -->
SyntaxError: syntax error, unexpected keyword_or, expecting ')'
Why is that? `puts(nil || 4)` does work, but I wonder why `or` doesn't. I thought the difference between the two was only in their operator precedence.
(I know the expression `nil or 4` doesn't seem useful, as it always returns `4`. It's just an example, for simplicity's sake. My actual expression is `Integer(ENV['WD'] or 4)`.)