Understanding syntax when adding to hash


#1

movies = {
    
  Forrest_Gump: 5,
    
}

puts "Welcome to your movie section \n  Type 'add' to add a movie \n  Type 'update' to update a movie \n Type 'display' to display a movie \n  Type 'delete' to delete a movie \n  Caution: anything else typed will result in 'error'"


user_input = gets.chomp
choice = user_input

case choice
when "add"
    puts "What is the name of the movie you would like to add?"
    title = gets.chomp
    puts "1-5, 5 being the greatest, what is your rating of this movie?"
    rating = gets.chomp
    puts movies[title] = rating
    puts "#{title}, has been added with a rating of #{rating}"

My question...how is puts movie[title] = rating storing the information in my hash? In other words, why would not movies[title, rating] work and without the "puts" in front?

Why does the puts not type this line out to the screen or does it "puts" it into my hash?

I continue to just hit the believe button and accept that this is the syntax of Ruby. However, I am trying to understand how the code is compiled via the Ruby language.


#3

YOUR QUESTION: "My question...how is puts movie[title] = rating storing the information in my hash? In other words, why would not movies[title, rating] work and without the "puts" in front?
ANSWER: YOU DON'T HAVE TO USE A "PUTS" BEFORE "MOVIE[TITLE]=RATING". "PUTS" IS USED TO DISPLAY CODE, NOT TO WRITE TO FILE. MAYBE SOMETHING WRONG WITH CODECADEMY?