Method: Hanami::Utils::Kernel.Integer
- Defined in:
- lib/hanami/utils/kernel.rb
permalink .Integer(arg) ⇒ Fixnum
Coerces the argument to be an Integer.
It’s similar to Ruby’s Kernel.Integer, but it doesn’t stop at the first error and raise an exception only when the argument can’t be coerced.
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/hanami/utils/kernel.rb', line 331 def self.Integer(arg) super rescue ArgumentError, TypeError, NoMethodError begin case arg when NilClass, ->(a) { a.respond_to?(:to_i) && numeric?(a) } arg.to_i else raise TypeError.new "can't convert #{inspect_type_error(arg)}into Integer" end rescue NoMethodError raise TypeError.new "can't convert #{inspect_type_error(arg)}into Integer" end rescue RangeError raise TypeError.new "can't convert #{inspect_type_error(arg)}into Integer" end |