Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/duration.rb
Overview
The following important additions are made to Numeric:
Numeric#weeks – Create a Duration object with given weeks Numeric#days – Create a Duration object with given days Numeric#hours – Create a Duration object with given hours Numeric#minutes – Create a Duration object with given minutes Numeric#seconds – Create a Duration object with given seconds
Instance Method Summary collapse
- #__numeric_old_method_missing ⇒ Object
-
#method_missing(method, *args) ⇒ Object
Intercept calls to .weeks, .days, .hours, .minutes and .seconds because Rails defines its own methods, so I’d like to prevent any redefining of Rails’ methods.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Intercept calls to .weeks, .days, .hours, .minutes and .seconds because Rails defines its own methods, so I’d like to prevent any redefining of Rails’ methods.
Example
140.seconds => #<Duration: 2 minutes and 20 seconds>
351 352 353 354 355 356 357 |
# File 'lib/duration.rb', line 351 def method_missing(method, *args) if [:weeks, :days, :hours, :minutes, :seconds].include? method Duration.new(method => self) else __numeric_old_method_missing(method, *args) end end |
Instance Method Details
#__numeric_old_method_missing ⇒ Object
340 |
# File 'lib/duration.rb', line 340 alias __numeric_old_method_missing method_missing |