Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env ruby
- movies = { skyfall: 8.5,
- avatar: 9,
- tron_legacy: 8.9
- }
- 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 all movies."
- puts "-- Type 'delete' to delete a movie."
- choice = gets.chomp
- case choice
- when "add"
- puts "What movie do you want to add?"
- title = gets.chomp
- if movies[title.to_sym].nil?
- puts "What's the rating? (Type a number 0 to 4.)"
- rating = gets.chomp
- movies[title.to_sym] = rating.to_i
- puts "#{title} has been added with a rating of #{rating}."
- else
- puts "That movie already exists! Its rating is #{movies[title.to_sym]}."
- end
- when "update"
- puts "What movie would you like to update?"
- title = gets.chomp
- if movies[title.to_sym].nil?
- puts "Movie not found!"
- else
- puts "What's the new rating? (Type a number 0 to 4.)"
- rating = gets.chomp
- movies[title.to_sym] = rating.to_i
- puts "#{title} has been updated with new rating of #{rating}."
- end
- when "display"
- puts movies.each { |k, v| puts "#{k}: #{v}" }
- when "delete"
- puts "What movie would you like to remove?"
- title = gets.chomp
- if movies[title.to_sym].nil?
- puts "Movie not found!"
- else
- movies.delete(movie)
- end
- else
- puts "Error!"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement