Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/duration.rb
Instance Method Summary collapse
- #__Numeric_method_missing ⇒ Object
-
#method_missing(method, *args) ⇒ Object
Intercept calls to #weeks, #days, #hours, #minutes, #seconds because Rails defines their 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, #seconds because Rails defines their own methods, so I’d like to prevent any redefining of Rails’ methods.
Example
140.seconds => #<Duration: 2 minutes and 20 seconds>
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/duration.rb', line 228 def method_missing(method, *args) case method when :weeks then Duration.new(Duration::WEEK * self) when :days then Duration.new(Duration::DAY * self) when :hours then Duration.new(Duration::HOUR * self) when :minutes then Duration.new(Duration::MINUTE * self) when :seconds then Duration.new(Duration::SECOND * self) else __Numeric_method_missing(method, *args) end end |
Instance Method Details
#__Numeric_method_missing ⇒ Object
217 |
# File 'lib/duration.rb', line 217 alias __Numeric_method_missing method_missing |