03/10 The Case Statement


movies = {
    "Interstellar" => 4.5,
    "Star wars" => 4

puts "Welcome to the Movie Rater!"
puts "What would you like to do?."
puts "--Add a movie"
puts "--Update a movie"
puts "--Display all movies"
puts "--Delete a movie"

choice = gets.chomp

case choice
    when "add" || "Add"
        puts "Added!"
    when "update" || "Update"
        puts "Updated!"
    when "display" || "Display"
        puts "Movies!"
    when "delete" || "Delete"
        puts "Deleted!"
    puts "Error!"

I know that I can use the .downcase! method in order to downcase the input given by the end user but I would like to know why it wont work like i have it listed above.


This is a boolean expression. and does not evaluate to a string.

case choice.downcase

is the way to go.

Something to try, for the fun of it...

case true
  when choice == 'add' || choice == 'Add'

but it obviously is not very compact.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.