Created
June 10, 2013 21:33
-
-
Save Jaltman429/5752536 to your computer and use it in GitHub Desktop.
hashes.rb
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
# Create Hashes for the following use-cases. | |
# A movie collection that organizes by genres | |
# Recipes with ingredients | |
# User profiles where each user has a list of favorite colors along with 3 | |
# personal essays, essay_1, essay_2, essay_3 | |
# 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. | |
movies = { | |
:action => ["Fast and furious", "Minority Report"], | |
:drama => ["Notebook", "SLPB"], | |
:comedy => ["Anchorman", "Goodfellas"] | |
} | |
puts movies[:comedy] | |
recipes = { | |
:sandwich => { | |
:ingredients => ['bread', 'meat', 'cheese'], | |
:instructions => ['combine it all'] | |
} | |
} | |
puts recipes[:sandwich][:instructions] | |
profiles = { | |
:guy1 => { | |
:colors => ['red', 'yellow', 'blue'], | |
:essays => { | |
:essay_1 => "The bridge", | |
:essay_2 => "The tunnel", | |
:essay_3 => "The house" | |
} | |
} | |
} | |
puts profiles[:guy1][:essays][:essay_2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment