Ruby Case Expression

Watch out! This tutorial is over 5 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.
Tutorial Difficulty Level    

The ruby case statement is similar to the C/C++/Java switch, but more directly related to the similar (and superior) structures from Pascal and Ada. First, it assumes that each case ends where the next one starts, without needing a break to terminate a case. Secondly, each case can be expressed rather generally, with a single value, a range of value, or a list containing some of each.

For this example, I’m using the fact the control statements have a return value. That’s not special to cases, and their value can be used or not, just as ifs.