Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/duration.rb

Instance Method Summary collapse

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_missingObject



217
# File 'lib/duration.rb', line 217

alias __Numeric_method_missing method_missing