Class: Fixnum

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/core_ext/fixnum.rb', line 8

def method_missing(method, *args, &block)
  if unit = method.to_s.scan(/^per_(second|minute|hour)$/).flatten.first
    self / 1.send(unit.to_sym).to_f
  else
    super
  end
end

Instance Method Details

#percentObject



4
5
6
# File 'lib/core_ext/fixnum.rb', line 4

def percent
  self
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/core_ext/fixnum.rb', line 16

def respond_to_missing?(method, include_private = false)
  method =~ /^per_(second|minute|hour)$/
end