A syntax for a tenary operator is:

(exp)? <if true> : <if false>

<if true> and <if false> is always the one object - I think that ruby
can't tell whether you're trying to call puts or push two or more
elements in these "fields". So use the parenthesized form to call a
function.

PS. Sorry for my not technical language ;).

Yours,
Martin

2011/7/23 Jesse Breuer <jesse.breuer / gmail.com>:
> 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"
>           ^
>
>
> It works however if I use this form:
> x == 2 ? puts("two") : puts("one")
> Could someone help me figure out why? Is there documentation somewhere
> on this?
>
> thanks
>
> --
> Posted via http://www.ruby-forum.com/.
>
>