Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#coerce

(::Numeric) -> [ ::Numeric, ::Numeric ]
int.coerce(numeric) → array

Returns an array with both a numeric and a int represented as Integer objects or Float objects.

This is achieved by converting numeric to an Integer or a Float.

A TypeError is raised if the numeric is not an Integer or a Float type.

Example
(0x3FFFFFFFFFFFFFFF+1).coerce(42)   #=> [42, 4611686018427387904]
See also #chr #denominator #ceildiv #digits also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0