Skip to content

Instantly share code, notes, and snippets.

@todlazarov
Created January 9, 2016 04:20
Show Gist options
  • Save todlazarov/65fdf8a6cbbe06f5a91d to your computer and use it in GitHub Desktop.
Save todlazarov/65fdf8a6cbbe06f5a91d to your computer and use it in GitHub Desktop.
# Given the munsters hash below
munsters = {
"Herman" => { "age" => 32, "gender" => "male" },
"Lily" => { "age" => 30, "gender" => "female" },
"Grandpa" => { "age" => 402, "gender" => "male" },
"Eddie" => { "age" => 10, "gender" => "male" },
"Marilyn" => { "age" => 23, "gender" => "female"}
}
# Modify the hash such that each member of the Munster family has an additional "age_group" key that has one of three values describing the age group the family member is in (kid, adult, or senior). Your solution should produce the hash below
# { "Herman" => { "age" => 32, "gender" => "male", "age_group" => "adult" },
# "Lily" => {"age" => 30, "gender" => "female", "age_group" => "adult" },
# "Grandpa" => { "age" => 402, "gender" => "male", "age_group" => "senior" },
# "Eddie" => { "age" => 10, "gender" => "male", "age_group" => "kid" },
# "Marilyn" => { "age" => 23, "gender" => "female", "age_group" => "adult" } }
# Note: a kid is in the age range 0 - 17, an adult is in the range 18 - 64 and a senior is aged 65+.
# hint: try using a case statement along with Ruby Range objects in your solution
puts munsters["Herman"]["age"]
munsters.each do |each|
puts [each]["age"]
case [each]["age"]
when 0..17
puts "kid"
when 18..64
puts "adult"
when 65..1000
puts "senior"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment