Skip to content

Instantly share code, notes, and snippets.

@tlux
Created February 10, 2015 23:36
Show Gist options
  • Select an option

  • Save tlux/4a372df564bd1281b04b to your computer and use it in GitHub Desktop.

Select an option

Save tlux/4a372df564bd1281b04b to your computer and use it in GitHub Desktop.
Age Calculator
class Age
attr_reader :birthday
def initialize(birthday)
@birthday = birthday.to_date
end
def age
today = Date.today
result = today.year - birthday.year
if today.month > birthday.month ||
(today.month == birthday.month && today.day >= birthday.day)
result -= 0
else
result -= 1
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment