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



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

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



2
3
4
# File 'lib/core_ext/fixnum.rb', line 2

def percent
  self
end

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

Returns:

  • (Boolean)


14
15
16
# File 'lib/core_ext/fixnum.rb', line 14

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