DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

A Simple Case Example

06.13.2010
| 2244 views |
  • submit to reddit
        Source: <a href="http://ruby-doc.org/core/classes/Range.html#M000704">Class: Range</a> [ruby-doc.org]
<snip>
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

</snip>