Prompting: Redux!


#1

movies = {
    Stepbrothers: "10"
}

puts "What would you like to do?"
    choice = gets.chomp

case choice
when "add"
    puts "Enter movie title"
        title = gets.chomp
    puts "Rate this movie"
        rating = gets.chomp
    
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else 
    puts "Error!"
end
 
Having trouble understanding how to: "Add that movie/rating pair to the movies hash and puts a message indicating the pair was added. (No need for to_sym or to_i just yet!)"


*figured it out* 
"movies[title]=rating"


#2

@james423

movies = {
    :Stepbrothers=> "10",
    :Matufin=> 9
}
#The =movies= VARIABLE has an associated Hash-Value
#A Hash consists of 1 or more =key-value= pairs 
# a =key-value= pair is often called a PROPERTY
# the =key-value= pairs are separated from eachother by a comma-,
# the =key-value= pairs are encapsulated by a pair of curly-brackets-{ }
#
#the =Stepbrothers= PROPERTY
#    the KEY =Stepbrothers= has an associated string-VALUE "10"
#the =Matufin= PROPERTY
#    the KEY =Matufin= has an associated number-VALUE 9
#movies = {
#    Stepbrothers: "10",   <==be aware of the comma-, separator
#    Matufin: 9
#}
#

#If you would use
puts movies
# you would see that internally in RUBY the Hash is represented as
# {:Stepbrothers=>"10", :Matufin=>9}
# the KEY =Stepbrothers= is actually a SYMBOL :Stepbrothers
#
#to get at the associated-Value of the =Stepbrothers= PROPERTY
#you would use
puts movies[:Stepbrothers]
#
#to add a new PROPERTY you would use
movies[:newfilm] = 5
#
#if use a gets.chomp
# you will generate a string-Value

newfilm = "Tango"
newvote = "5"
movies[newfilm.to_sym] = newvote
newfilm = "Matrix"
newvote = "4"
movies[newfilm.to_sym] = newvote.to_i
puts movies