The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Frosted MiniColons

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Frosted MiniColons Posted: Feb 7, 2005 2:56 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Frosted MiniColons
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

It must have been around revision 1.260 of parse.y that colons came into expression play. And, progressively, colons are getting more airtime in Ruby 1.9. Yet another thing I forgot to mention in What’s Shiny and New in Ruby 1.8.0?

Rather handy for laying out a short if..elsif series:

 unit_of_time =
   if num < 60:              "second" 
   elsif num < 60 * 60:      "minute" 
   elsif num < 60 * 60 * 24: "hour" 
   else                      "day" 
   end

Also, in case..when:

 unit_of_time =
   case num
   when 0..60:           "second" 
   when 0..60 * 60:      "minute" 
   when 0..60 * 60 * 24: "hour" 
   else                  "day" 
   end

Did you know you can also use keyword then in place of all the colons above?

And if you want to your colon use to come to a head, try this in Ruby 1.9:

  me = {name: "_why", url: "http://redhanded.hobix.com",
        photo: "http://whytheluckystiff.net/i.home/boy.gif"}

Read: Frosted MiniColons

Topic: Releasing ParseTree 1.3.3 Previous Topic   Next Topic Topic: [ANN] Wee 0.7.0 + Tutorial Videos

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use