A Basic Case Statement
The syntax for case statements (or switch statements) is a little different for each language. I often confuse the Ruby and JavaScript syntax or wonder if I need to be using a colon anywhere.
Here is a demonstration of how to write a basic case statement in Ruby.
This next example demonstrates two things. First, you can make things terser with the then
syntax. Second, the case statement does an implicit return of whatever the last value is from the evaluated case. So it can be used as part of a variable assignment.
Last updated