Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns an array with both a numeric and a big represented as Bignum objects.
This is achieved by converting numeric to a Bignum.
A TypeError is raised if the numeric is not a Fixnum or Bignum type.
(0x3FFFFFFFFFFFFFFF+1).coerce(42)   #=> [42, 4611686018427387904]
               static VALUE
rb_int_coerce(VALUE x, VALUE y)
    if (RB_INTEGER_TYPE_P(y)) {
        return rb_assoc_new(y, x);
    else {
        x = rb_Float(x);
        y = rb_Float(y);
        return rb_assoc_new(y, x);

Was this page useful?