Method: Lotus::Utils::Kernel.BigDecimal
- Defined in:
- lib/lotus/utils/kernel.rb
.BigDecimal(arg) ⇒ BigDecimal
Coerces the argument to be a BigDecimal.
421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/lotus/utils/kernel.rb', line 421 def self.BigDecimal(arg) case arg when ->(a) { a.respond_to?(:to_d) } then arg.to_d when Float, Complex, Rational BigDecimal(arg.to_s) when ->(a) { a.to_s.match(NUMERIC_MATCHER) } BigDecimal.new(arg) else raise TypeError.new "can't convert #{inspect_type_error(arg)}into BigDecimal" end rescue NoMethodError raise TypeError.new "can't convert #{inspect_type_error(arg)}into BigDecimal" end |