Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns the predecessor of self (equivalent to self - 1):
1.pred  #=> 0
-1.pred #=> -2
Related: Integer#succ (successor value).
 
               static VALUE
rb_int_pred(VALUE num)
{
    if (FIXNUM_P(num)) {
        long i = FIX2LONG(num) - 1;
        return LONG2NUM(i);
    }
    if (RB_BIGNUM_TYPE_P(num)) {
        return rb_big_minus(num, INT2FIX(1));
    }
    return num_funcall1(num, '-', INT2FIX(1));
}
            

Was this page useful?