Last active
December 10, 2017 18:45
-
-
Save max-power/58317b8d7920e3ec436f6212debf6a1a to your computer and use it in GitHub Desktop.
Ruby Age Calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Age | |
def initialize(dob) | |
@dob = dob | |
end | |
def now | |
at Time.now | |
end | |
def at(date) | |
(f(date) - f(@dob)) / 10000 | |
end | |
private | |
def f(date) | |
date.strftime('%Y%m%d').to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment