class AgeCalculator

Constants

VERSION

Public Class Methods

new(birthday) click to toggle source
# File lib/age_calculator.rb, line 6
def initialize(birthday)
  @birthday = birthday

  unless @birthday.is_a?(Date)
    fail ArgumentError, "#{@birthday.inspect} is not a date"
  end
end

Public Instance Methods

age(asof: nil) click to toggle source
# File lib/age_calculator.rb, line 14
def age(asof: nil)
  ((asof || today).strftime('%Y%m%d').to_i - @birthday.strftime('%Y%m%d').to_i) / 10000
end
today() click to toggle source
# File lib/age_calculator.rb, line 18
def today
  Time.respond_to?(:zone) ? Time.zone.today : Date.today
end