implements Date#age_in_years extension method
This commit is contained in:
8
lib/date_ext.rb
Normal file
8
lib/date_ext.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module AgeInYears
|
||||
def age_in_years(now = Time.now.utc.to_date)
|
||||
# reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263
|
||||
now.year - year - ((now.month > month || (now.month == month && now.day >= day)) ? 0 : 1)
|
||||
end
|
||||
end
|
||||
|
||||
Date.include(AgeInYears)
|
||||
Reference in New Issue
Block a user