Method: Float#coerce

Defined in:
numeric.c

#coerce(other) ⇒ Array

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

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.

Returns:



1120
1121
1122
1123
1124
# File 'numeric.c', line 1120

static VALUE
flo_coerce(VALUE x, VALUE y)
{
    return rb_assoc_new(rb_Float(y), x);
}