Class: Numeric
Instance Method Summary collapse
- #days ⇒ Object (also: #day)
- #hours ⇒ Object (also: #hour)
- #minutes ⇒ Object (also: #minute)
- #months ⇒ Object (also: #month)
-
#seconds ⇒ Object
(also: #second)
Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
- #weeks ⇒ Object (also: #week)
- #years ⇒ Object (also: #year)
Instance Method Details
#days ⇒ Object Also known as: day
30 31 32 |
# File 'lib/vendor/numeric_ext.rb', line 30 def days self * 24.hours end |
#hours ⇒ Object Also known as: hour
25 26 27 |
# File 'lib/vendor/numeric_ext.rb', line 25 def hours self * 3600 end |
#minutes ⇒ Object Also known as: minute
20 21 22 |
# File 'lib/vendor/numeric_ext.rb', line 20 def minutes self * 60 end |
#months ⇒ Object Also known as: month
40 41 42 |
# File 'lib/vendor/numeric_ext.rb', line 40 def months self * 31.days end |
#seconds ⇒ Object Also known as: second
Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
These methods use Time#advance for precise date calculations when using from_now, ago, etc. as well as adding or subtracting their results from a Time object. For example:
# equivalent to Time.current.advance(months: 1)
1.month.from_now
# equivalent to Time.current.advance(years: 2)
2.years.from_now
# equivalent to Time.current.advance(months: 4, years: 5)
(4.months + 5.years).from_now
15 16 17 |
# File 'lib/vendor/numeric_ext.rb', line 15 def seconds self end |
#weeks ⇒ Object Also known as: week
35 36 37 |
# File 'lib/vendor/numeric_ext.rb', line 35 def weeks self * 7.days end |
#years ⇒ Object Also known as: year
45 46 47 |
# File 'lib/vendor/numeric_ext.rb', line 45 def years self * 365.days end |