Module: Agery

Defined in:
lib/agery.rb,
lib/agery/version.rb

Constant Summary collapse

AGE_OVER =
/^over_(0|[1-9]\d*)$/.freeze
AGE_UNDER =
/^under_([1-9]\d*)$/.freeze
VERSION =
"2.0.0"

Class Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/agery.rb', line 44

def method_missing(method, *)
  case method.to_s
  when AGE_OVER  then to_age_a($1.to_i)
  when AGE_UNDER then to_age_a($1.to_i - 1)
  else super
  end
end

Class Attribute Details

.adultObject

Returns the value of attribute adult.



12
13
14
# File 'lib/agery.rb', line 12

def adult
  @adult
end

.childObject

Returns the value of attribute child.



12
13
14
# File 'lib/agery.rb', line 12

def child
  @child
end

.infantObject

Returns the value of attribute infant.



12
13
14
# File 'lib/agery.rb', line 12

def infant
  @infant
end

.seniorObject

Returns the value of attribute senior.



12
13
14
# File 'lib/agery.rb', line 12

def senior
  @senior
end

.teenagerObject

Returns the value of attribute teenager.



12
13
14
# File 'lib/agery.rb', line 12

def teenager
  @teenager
end

Instance Method Details

#adultsObject Also known as: adult



15
16
17
# File 'lib/agery.rb', line 15

def adults
  to_age_a Agery.adult
end

#childrenObject Also known as: child



25
26
27
# File 'lib/agery.rb', line 25

def children
  to_age_a Agery.child
end

#infantsObject Also known as: infant



20
21
22
# File 'lib/agery.rb', line 20

def infants
  to_age_a Agery.infant
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/agery.rb', line 40

def respond_to?(method, *)
  super || AGE_OVER === method.to_s || AGE_UNDER === method.to_s
end

#seniorsObject Also known as: senior



35
36
37
# File 'lib/agery.rb', line 35

def seniors
  to_age_a Agery.senior
end

#teenagersObject Also known as: teenager



30
31
32
# File 'lib/agery.rb', line 30

def teenagers
  to_age_a Agery.teenager
end