Skip to content

Instantly share code, notes, and snippets.

@ryantownsend
Created March 18, 2014 06:50
Show Gist options
  • Select an option

  • Save ryantownsend/9614810 to your computer and use it in GitHub Desktop.

Select an option

Save ryantownsend/9614810 to your computer and use it in GitHub Desktop.
AGE_CATEGORIES = {
:child => 0..12,
:teenager => 13..19,
:young => 20..28,
:adult => 29..50,
:senior => 50..120
}
def age_group_lookup(age)
AGE_CATEGORIES.find { |(k, v)| v.cover?(age) }.first
end
age_group_lookup(5) # => :child
age_group_lookup(15) # => :teenager
age_group_lookup(29) # => :adult
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment