From: Phillip Gawlowski Date: 2009-12-31T11:35:43+09:00 Subject: Re: Why can't I use "or" here? On 31.12.2009 03:24, Albert Schlef wrote: > (The problem is in both Ruby 1.8 and Ruby 1.9) > > The expression: > > puts(nil || 4) > > works as expected. It prints '4'. > > But this expression: > > puts(nil or 4) > > fails... it is a syntax error, for some mysterious reason. > > Why? I thought the only diference between "or" and "||" is the > precedence. Hm, on Ruby 1.9.1 I get: irb(main):001:0> puts nil or 4 => 4 irb(main):002:0> puts(nil or 4) SyntaxError: (irb):2: syntax error, unexpected keyword_or, expecting ')' puts(nil or 4) ^ from C:/Ruby19/bin/irb:12:in `
' irb(main):003:0> puts(nil || 4) 4 => nil This seems like a bug to me, since parenthesis *should* "only" make method calls and precedent unambigious. -- Phillip Gawlowski