Why doesnt this code work?


#1

Ok so I am doing hashes on ruby and this code should totally work I even looked up some solutions. Well it keeps saying "error does not add movie to the movies hash" or whatever. here is the code I am using
movies= {
:lord_of_the_rings => 4
}

puts "Please add a movie"
choice = gets.chomp

case choice
when "add"
puts "What is the title?"
title = gets.chomp

puts "What is its rating?(0-4)"
rating = gets.chomp

movies = [title, rating]
puts "#{title} added to list with a rating of #{rating}"

when "update"
puts "Updated!"

what is the problem here?


#2

also i tried using movies[title]=rating

this also does not work in case someone is going to recommend me using that.


#3

Your code with movies[title] = rating should work. (Not with movies = [title, rating] though)

Assuming you didn't forget the last end keyword of course.