Skip to content
instance method

Float#coerce

(::Numeric) -> [ ::Float, ::Float ]
coerce(other) → array

Returns a 2-element array containing other converted to a Float and self:

Example
f = 3.14                 # => 3.14
f.coerce(2)              # => [2.0, 3.14]
f.coerce(2.0)            # => [2.0, 3.14]
f.coerce(Rational(1, 2)) # => [0.5, 3.14]
f.coerce(Complex(1, 0))  # => [1.0, 3.14]

Raises an exception if a type conversion fails.

See also #ceil #denominator #arg #divmod also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0