From: botp Date: 2011-07-23T09:14:30+09:00 Subject: Re: using "puts" in ternary operator On Sat, Jul 23, 2011 at 7:18 AM, Jesse Breuer wrote: > I find that I get errors if I use "puts" in it's standard form in a > ternary operator > x == 2 ? puts "two" : puts "one" > > error is: > > SyntaxError: (irb):3: syntax error, unexpected tSTRING_BEG, expecting > keyword_do or '{' or '(' > x == 2 ? puts "two" : puts "one" >               ^ > (irb):3: syntax error, unexpected ':', expecting $end > x == 2 ? puts "two" : puts "one" >                     ^ imho, ruby is trying to read it as: x == 2 ? puts ("two" : puts "one") it reads the puts first, but then it encounters the colon, so... > > It works however if I use this form: > x == 2 ? puts("two") : puts("one") or: x == 2 ? (puts "two" ) : (puts "one" ) > Could someone help me figure out why? Is there documentation somewhere > on this? use parens to help the interpreter kind regards -botp