End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Integer#pred
int.pred → integer
numeric.c
View on GitHub ↗
static VALUE
rb_int_pred(VALUE num)
{
if (FIXNUM_P(num)) {
long i = FIX2LONG(num) - 1;
return LONG2NUM(i);
}
if (RB_TYPE_P(num, T_BIGNUM)) {
return rb_big_minus(num, INT2FIX(1));
}
return num_funcall1(num, '-', INT2FIX(1));
}
Returns the predecessor of int, i.e. the Integer equal to int-1.
Example
1.pred #=> 0 (-1).pred #=> -2