From: furufuru@... (Ryo Furue) Date: 2001-08-07T21:25:06+09:00 Subject: [ruby-talk:19283] Help with ternary operator syntax and grammar Hi there, I'm fairly new to Ruby and writing small scripts with the pickaxe book. I can't understand what's wrong with this: cond = true print (cond? ", " : "\n") which gives you a "parse error" at line 2. The following gives you the same error (first line elided): print cond? ", " : "\n" Also, this print (cond)? ", " : "\n" prints "true", not ", ". What's going on? Yet, the following prints what you expect (a comma followed by a blank) print ((cond)? ", " : "\n") Aha, I got it, what I needed were the parentheses around the whole expression! BUT, the following gives you the parse error again print (cond == true? ", " : "\n") OK, I see, I need both pairs of parentheses. *BUT*, the following program works! cond = 1 print (cond == 1? ", " : "\n") I'm clueless. Could someone enlighten me by explaining the underlying rules? By the way, I like Ruby very much. As soon as I came to know it, I abandoned Perl. Cheers, Ryo