From: Bertram Scharpf Date: 2009-12-31T23:15:14+09:00 Subject: Re: Why can't I use "or" here? Hi, Am Donnerstag, 31. Dez 2009, 11:24:26 +0900 schrieb Albert Schlef: > (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. There's a difference between _grouping_ parentheses (like begin...end) and _method_ _call_ parentheses: puts (nil or 4) # vs. puts( nil or 4) See: irb(main):001:0> $-w = true => true irb(main):002:0> puts( nil or 4) SyntaxError: compile error (irb):2: syntax error, unexpected kOR, expecting ')' puts( nil or 4) ^ from (irb):2 irb(main):003:0> puts (nil or 4) (irb):3: warning: (...) interpreted as grouped expression 4 => nil Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany * Support `String#notempty?': .