Created
July 23, 2013 16:35
-
-
Save TGOlson/6063907 to your computer and use it in GitHub Desktop.
Simple CRUD app that stores info in a Hash. From lesson 6 of Code Academy Ruby Track.
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 = { | |
Iron_Man: 3, | |
Fast_Five: 4, | |
Sharknado: 5 | |
} | |
puts 'Do you want to ADD, UPDATE, DISPLAY, or DELETE?' | |
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 is the rating of #{title}?" | |
rating = gets.chomp | |
movies[title.to_sym] = rating.to_i | |
puts "#{title} with rating of #{rating} was added." | |
else | |
puts "#{title} already entered." | |
end | |
when 'update' | |
puts 'What movie do you want to update?' | |
title = gets.chomp | |
if movies[title.to_sym].nil? | |
puts "#{title} does not exist." | |
else | |
puts "What is the rating of #{title}?" | |
rating = gets.chomp | |
movies[title.to_sym] = rating.to_i | |
puts "#{title} was updated with a rating of #{rating}." | |
end | |
when 'display' | |
movies.each { |movie,rating| puts "#{movie}: #{rating}" } | |
when 'delete' | |
puts 'What movie do you want to delete?' | |
title = gets.chomp | |
if movies[title.to_sym].nil? | |
puts "#{title} does not exist." | |
else | |
movies.delete(title) | |
end | |
else | |
puts 'You messed.' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment