Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created September 30, 2013 22:07
Show Gist options
  • Save ahimmelstoss/6771021 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6771021 to your computer and use it in GitHub Desktop.
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] << "streamers"
# Add a supply to memorial day.
holiday_supplies[:spring][:memorial_day] << "flag"
# Add a new holiday to any season with supplies.
holiday_supplies[:fall] = {:halloween => ["pumpkin", "skeleton"]}
# Write a method to collect all Winter supplies from all the winter holidays.
def winter_suppliers(supplies_hash, season)
supplies_hash[season].each do |holiday, supplies|
puts supplies
end
end
winter_suppliers(holiday_supplies, :winter)
# Write a loop to list out all the supplies you have for each holiday and the season.
holiday_supplies.each do |season, holiday|
puts "#{season.capitalize}:"
holiday.each do |holiday, supplies|
puts "#{holiday.capitalize}: #{supplies.join(" and ")}"
end
end
# Write a method to collect all holidays with BBQ.
# holidays_with_bbqs(holiday_supplies) #=> [:fourth_of_july, :memorial_day]
def holidays_with_bbqs(holiday_supplies)
holiday_supplies.each do |season, holiday|
holiday.each do |holiday, supplies|
if supplies.include?("BBQ")
puts holiday
end
end
end
end
holidays_with_bbqs(holiday_supplies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment