Class: Numeric

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/active_decimal.rb', line 105

def method_missing(meth, *args, &block)

  if ActiveDecimal::BIG_NUMBERS[meth]
    val = self * ActiveDecimal::BIG_NUMBERS[meth]
    return val.to_i == val ? val.to_i : val
  end

  if ActiveDecimal::SINGULAR_SMALL_NUMBERS[meth]
    if self <= 1 and self > 0
      return Rational(self, ActiveDecimal::SINGULAR_SMALL_NUMBERS[meth])
    else
      raise ActiveDecimal::BadGrammar
    end
  end

  if ActiveDecimal::PLURAL_SMALL_NUMBERS[meth]
    if self > 1 or self <= 0
      return Rational(self, ActiveDecimal::PLURAL_SMALL_NUMBERS[meth])
    else
      raise ActiveDecimal::BadGrammar
    end
  end

  super
end