Class: Age
- Inherits:
-
Object
- Object
- Age
- Defined in:
- lib/age.rb,
lib/age/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#birth ⇒ Object
Returns the value of attribute birth.
-
#end ⇒ Object
Returns the value of attribute end.
Instance Method Summary collapse
-
#initialize(options) ⇒ Age
constructor
A new instance of Age.
- #inspect ⇒ Object
- #to_i ⇒ Object
- #years ⇒ Object
Constructor Details
#initialize(options) ⇒ Age
Returns a new instance of Age.
7 8 9 10 |
# File 'lib/age.rb', line 7 def initialize() @birth = [:birth] || DateTime.now.offset(0) @end = [:end] || DateTime.now.offset(0) end |
Instance Attribute Details
#birth ⇒ Object
Returns the value of attribute birth.
5 6 7 |
# File 'lib/age.rb', line 5 def birth @birth end |
#end ⇒ Object
Returns the value of attribute end.
5 6 7 |
# File 'lib/age.rb', line 5 def end @end end |
Instance Method Details
#inspect ⇒ Object
27 28 29 |
# File 'lib/age.rb', line 27 def inspect years.inspect end |
#to_i ⇒ Object
23 24 25 |
# File 'lib/age.rb', line 23 def to_i years end |
#years ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/age.rb', line 12 def years leep_year = 2004 end_with_leep_year = DateTime.new(leep_year, @end.month, @end.day, @end.hour, @end.min, @end.sec) birth_with_leep_year = DateTime.new(leep_year, @birth.month, @birth.day, @birth.hour, @birth.min, @birth.sec) if end_with_leep_year < birth_with_leep_year @end.year - @birth.year - 1 else @end.year - @birth.year end end |