Skip to content

Instantly share code, notes, and snippets.

@TGOlson
Created July 23, 2013 16:35
Show Gist options
  • Save TGOlson/6063907 to your computer and use it in GitHub Desktop.
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.
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