Home News Feeds DZone A simple case example
Sep 10
Friday
A simple case example PDF Print E-mail
Sunday, 13 June 2010 03:54
Source: Class: Range [ruby-doc.org]

Returns true if obj is an element of rng, false otherwise. Conveniently, === is the comparison operator used by case statements.

case 79
when 1..50 then print "low\n"
when 51..75 then print "medium\n"
when 76..100 then print "high\n"
end

produces:

high

Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/Ic-BAvxwhLw/11613

 
Home News Feeds DZone A simple case example