When add or 1


How can I enter this so that gets.chomp will run the add when "add" is typed or "1" is typed?

In the example on the first page the author shows only with "add"

I would like to accept either, or.


You need this lesson:


And this lesson:



I've already tried that though, keep getting an error message. My code is

when "add" || 1
    puts "What movie would you like to add?"
    title = gets.chomp
    puts "Rate the movie from 1 to 5"
    rating = gets.chomp
    movies[title] = rating
    puts "#{title} has been added with a rating of #{rating}."

when "add" || 1

Why does one of your value has quotes and one doesn't? As far as I know, the user will always provide you with characters, not integers ^^.

EDIT: Nevermind, the syntax is different for multiple conditions in a when, use the comma instead:

when value1, value2

Sorry for the confusion.


There were quotes because the user would type either “add” or 1. Option 1 is add.

I want to provide multiple ways for the user to enter an option.

ie) when “add” || “Add” || “ADD” | 1 etc.


but thanks for your edit… it works. Confusing that the syntax is different for multiple conditions for a case statement, but lesson learned :slight_smile: