coerce(p1) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
static VALUE
nurat_coerce(VALUE self, VALUE other)
{
    switch (TYPE(other)) {
      case T_FIXNUM:
      case T_BIGNUM:
        return rb_assoc_new(f_rational_new_bang1(CLASS_OF(self), other), self);
      case T_FLOAT:
        return rb_assoc_new(other, f_to_f(self));
      case T_RATIONAL:
        return rb_assoc_new(other, self);
      case T_COMPLEX:
        if (k_exact_p(RCOMPLEX(other)->imag) && f_zero_p(RCOMPLEX(other)->imag))
            return rb_assoc_new(f_rational_new_bang1
                                (CLASS_OF(self), RCOMPLEX(other)->real), self);
    }

    rb_raise(rb_eTypeError, "%s can't be coerced into %s",
             rb_obj_classname(other), rb_obj_classname(self));
    return Qnil;
}
Register or log in to add new notes.