Ternarys

1 view
Skip to first unread message

Scott Hofmann

unread,
Jun 13, 2013, 8:09:36 AM6/13/13
to cincin...@googlegroups.com

Hi all,

I can follow the way ruby way to do a ternary but I’m expecting it to be written differently:

 

correct ternary:

                puts 5 < 6 ? "five is less than six !" : "six is not less than five."

 

Here is what trips me up…

- why “puts” before 5 < 6?  I’m trying to evaluate 5 and 6 not put it to the screen yet?

- when I get true or false from the evaluation I then want to put the string to the screen so why not have the put within the true expression area and false expression area of my ternary?

                (test ? true expression : false expression)?

 

So I would expect it to be written like this:

                5 < 6 ? puts "five is less than six !" : puts "six is not less than five."

 

Anyone care to comment on why my logic is failed? ...other than it does not work that way J

 

- Scott

 

Michael Guterl

unread,
Jun 13, 2013, 9:19:36 AM6/13/13
to cincin...@googlegroups.com
Your expected example does not work due to a parse error. In this case you need the parenthesis:

5 < 6 ? puts("five is less than six !") : puts("six is not less than five.")


Reply all
Reply to author
Forward
0 new messages