instance method
Float#coerce
(::Numeric) -> [ ::Float, ::Float ]
coerce(other) → array
numeric.c
View on GitHub ↗
static VALUE
flo_coerce(VALUE x, VALUE y)
{
return rb_assoc_new(rb_Float(y), x);
}
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.