Skip to content

Instantly share code, notes, and snippets.

@sarony
Created September 30, 2013 21:44
Show Gist options
  • Select an option

  • Save sarony/6770752 to your computer and use it in GitHub Desktop.

Select an option

Save sarony/6770752 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"]
}
}
# winter_suppliers(holiday_supplies)
# # How would you access the second supply for the forth_of_july? ex: holiday_supplies[:spring][:memorial_day][0]
holiday_supplies[:summer][:forth_of_july][1]
# # Add a supply to a Winter holiday.
holiday_supplies[:winter][:christmas]<<"Tree"
# puts holiday_supplies[:winter][:christmas]
# # Add a supply to memorial day.
holiday_supplies[:spring][:memorial_day]<<"Corn"
# puts holiday_supplies[:spring][:memorial_day]
# # Add a new holiday to any season with supplies.
holiday_supplies[:fall][:halloween]=["Pumpkin", "Candy"]
# puts holiday_supplies[:fall]
# Write a method to collect all Winter supplies from all the winter holidays. ex: winter_suppliers(holiday_supplies) #=> ["Lights", "Wreath", etc]
def winter_suppliers(holiday_supplies)
holiday_supplies.each do |season, holidays|
holidays.select do |holiday, supplies|
supplies
end
end
end
# Write a loop to list out all the supplies you have for each holiday and the season.
holiday_supplies.each do |season, holidays|
# puts "#{season}"
holidays.each do |holiday, supplies|
holiday_name=holiday.to_s.split("_").join(" ").capitalize
supplies.each do |supply|
puts "It's #{season}! Which means it's time for #{holiday_name}. You're gonna need this: #{supply}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment