Method: Money::Parsing::ClassMethods#from_numeric
- Defined in:
- lib/money/money/parsing.rb
#from_numeric(value, currency = Money.default_currency) ⇒ Money
Converts a Numeric value into a Money object treating the value as dollars and converting them to the corresponding cents value, according to currency subunit property, before instantiating the Money object.
This method relies on various Money.from_* methods and tries to forwards the call to the most appropriate method in order to reduce computation effort. For instance, if value is an Integer, this method calls Money.from_fixnum instead of using the default Money.from_bigdecimal which adds the overload to converts the value into a slower BigDecimal instance.
223 224 225 226 227 228 229 230 231 232 |
# File 'lib/money/money/parsing.rb', line 223 def from_numeric(value, currency = Money.default_currency) case value when Fixnum from_fixnum(value, currency) when Numeric from_bigdecimal(BigDecimal.new(value.to_s), currency) else raise ArgumentError, "`value' should be a Numeric object" end end |