Key Concepts

Review core concepts you need to learn to master this subject

Ruby Case Statement

tv_show = "Bob's Burgers" case tv_show when "Archer" puts "I don't like the voice of Archer." when "Bob's Burgers" puts "I love the voice of Bob Belcher." else puts "I don't know who voices this cartoon." end # => I love the voice of Bob Belcher. #In this example, a case statement is used to check for multiple possible values of tv_show. Since tv_show is "Bob's Burgers", the second when is evaluated to true. If none of the conditions were met, Ruby would evaluate the else statement.

In Ruby, a case statement is a more concise alternative to an if/else statement that contains many conditions.

The Zen of Ruby
Lesson 1 of 2