Created
October 11, 2013 20:39
-
-
Save andersr/6941672 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Lab: https://gist.github.com/aviflombaum/e6e5478ab9f59430b94a | |
# holiday hashes | |
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] | |
}, | |
:fall => { | |
:thanksgiving => ["Turkey"] | |
}, | |
:spring => { | |
:memorial_day => ["BBQ"] | |
} | |
} | |
# How would you access the second supply for the forth_of_july? | |
holiday_supplies[:summer][:forth_of_july][1] | |
# Add a supply to a Winter holiday. | |
holiday_supplies[:winter][:new_years] << "Cups" | |
# Add a supply to memorial day. | |
holiday_supplies[:spring][:memorial_day] << "Hot Dogs" | |
# Add a new holiday to any season with supplies. | |
holiday_supplies[:winter][:chanukah] = [] | |
# Write a method to collect all Winter supplies | |
# from all the winter holidays. ex: | |
holiday_supplies.select{|season,holidays| season == "winter"} | |
def collect_supplies(hash, season) | |
return if ![:winter, :summer, :fall, :spring] | |
include?(season.downcase.to_sym) | |
hash[season.downcase.to_sym].collect do |holiday, supplies| | |
supplies | |
end | |
end | |
collect_supplies(holiday_supplies,:winter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment