Method: Hanami::Utils::Kernel.Float
- Defined in:
- lib/hanami/utils/kernel.rb
permalink .Float(arg) ⇒ Float
Coerces the argument to be a Float.
It’s similar to Ruby’s Kernel.Float, but it doesn’t stop at the first error and raise an exception only when the argument can’t be coerced.
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/hanami/utils/kernel.rb', line 551 def self.Float(arg) super rescue ArgumentError, TypeError begin case arg when NilClass, ->(a) { a.respond_to?(:to_f) && numeric?(a) } arg.to_f else raise TypeError.new "can't convert #{inspect_type_error(arg)}into Float" end rescue NoMethodError raise TypeError.new "can't convert #{inspect_type_error(arg)}into Float" end rescue RangeError raise TypeError.new "can't convert #{inspect_type_error(arg)}into Float" end |