Created
March 12, 2013 20:43
-
-
Save vpivo/5146831 to your computer and use it in GitHub Desktop.
To improve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
movies = { gone_with_the_wind: 3, the_lion_king: 4, the_matrix: 4 } | |
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 a move." | |
puts "--Type 'delete' to delete a movie." | |
choice = gets.chomp.downcase | |
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 rating would you like to give #{title}?" | |
rating = gets.chomp | |
movies[title.to_sym] = rating.to_i | |
puts "#{title} has been updated with new rating of #{rating}." | |
end | |
when "display" | |
movies.each do |i,e| | |
puts "#{i}: #{e}" | |
end | |
when "delete" | |
puts "What movie would you like to delete?" | |
tile = gets.chomp | |
if movies[title.to_sym].nil? | |
puts "That movie does not exist!" | |
else | |
movies.delete(title) | |
end | |
else | |
puts "Error!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment