Context: just started learning Ruby, the code below is a part of a slightly longer program, but I only need some help with the first part, and I may not articulate my problem clearly enough, so apologies in advance
Question: I've marked the problem parts of the program. If I have a hash with strings and I want the if-else statement to identify user input, regardless of how a user enters the movie title (e.g. different spacing, capitalization, or without quotation marks) as the same as those in the hash and output the else statement, how would I go about doing that? Thank you
movies = {
"Lord of the Rings" => 4, # <= this
Inception: 4,
"Hurt Locker" => 3.5, # <= this
Mother: 4
}
puts "What would you like to do?"
puts "-- Type 'add' to add a movie."
puts "-- Type 'update' to update a movie."
puts "-- Type 'display' to display a movie."
puts "-- Type 'delete' to delete a movie."
choice = gets.chomp
case choice
when "add"
puts "What movie would you like to add? "
title = gets.chomp
if movies[title.to_sym].nil?
puts "What rating does the movie have? "
rating = gets.chomp
movies[title.to_sym] = rating.to_i
else
# and this
# v
puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
end
end