Skip to content

Instantly share code, notes, and snippets.

@joegiralt
Created June 10, 2013 21:58
Show Gist options
  • Save joegiralt/5752773 to your computer and use it in GitHub Desktop.
Save joegiralt/5752773 to your computer and use it in GitHub Desktop.
hashes
# Create Hashes for the following use-cases.
# A movie collection that organizes by genres
movies = {
"horror" => ["night of the living dead", "exorcist"],
"adventure" => ["return of the jedi", "romancing the stone"],
"comedy" => ["dumb and dumber", "fargo"]
}
# Recipes with ingredients
recipes = {
"fried eggs" => ["salt", "two eggs", "oil"],
"popcorn" => ['unpopped corn','salt',"oil"]
}
# User profiles where each user has a list of favorite colors along with 3
#personal essays, essay_1, essay_2, essay_3
users = {
:user1 => {
:essays => ["essay_1","essay_2", "essay_3"],
:favorite_colors => ["red","green","blue"]
},
:user2 => {
:essays => ["essay_1","essay_2", "essay_3"],
:favorite_colors => ["red","green","blue"]
}
}
puts users[:user1][:essays][0]
# Just be creative, create a bunch of fake data just for the practice of how
#you would store this data in a structured hash.
#Feel free to create a single file, hashes.rb
#with a bunch of these and send them to me for review.
#There are really no wrong answers -
#there are just more logical ways of storing this sort of data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment