From: David Masover Date: 2009-12-31T12:12:17+09:00 Subject: Re: Why can't I use "or" here? On Wednesday 30 December 2009 08:35:43 pm Phillip Gawlowski wrote: > 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 Specifically, the parens around the method call. Want to see something even weirder? irb(main):001:0> puts(nil or) SyntaxError: (irb):1: syntax error, unexpected keyword_or, expecting ')' puts(nil or) ^ from /home/ruby19/bin/irb:12:in `
' irb(main):002:0> puts(nil or 4) SyntaxError: (irb):2: syntax error, unexpected keyword_or, expecting ')' puts(nil or 4) ^ from /home/ruby19/bin/irb:12:in `
' irb(main):003:0> (nil or 4) => 4 irb(main):004:0> puts((nil or 4)) 4 => nil irb(main):005:0>