Created
February 10, 2015 23:36
-
-
Save tlux/4a372df564bd1281b04b to your computer and use it in GitHub Desktop.
Age Calculator
This file contains hidden or 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 | |
| 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