7. Update


#1
movies = {
  "The Lord of the Rings" => 4
  }

puts "Enter a command"
choice = gets.chomp

case choice  
  when "update"
  puts "Enter the movie you would like to update"
	title = gets.chomp
  if movies[title].nil?
    puts "That movie (#{title}) is not on the list"
  else
    puts "Enter a new rating!"
    movies[rating] = gets.chomp
    puts "#{title} has been updated with a new rating of #{rating}"
    puts movies
  end

I have a question in regard to the update case. Is “movies[rating] = gets.chomp” correct? The solutions has:

    rating = gets.chomp
    movies[title.to_sym] = rating.to_i

The program still passes my code but when I put it again, it still gives me the old rating:

The Lord of the Rings has been updated with a new rating of 
{"The Lord of the Rings"=>4, nil=>"3"}

#2

No, it is not.

puts "Enter a new rating!"
rating =  gets.chomp
movies[title] = rating.to_i