Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 960618

Pages: 1
Phrogz
Unregistered




Ternary operator in Ruby, also
      #34210 - 07/18/06 03:45 PM

The comment leading into the code using if...then is that Ruby does not have a ternary operator. This is not true - Ruby has the ternary operator (although the syntax requires spaces around the characters to disambiguate some cases).

Code:
puts (if 23.odd? then "23 odd" else "23 even" end)
puts( 23.odd? ? "23 odd" : "23 even" )



Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 6841

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5