End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Integer#<=>
int <=> numeric → -1, 0, +1, or nil
numeric.c
View on GitHub ↗
VALUE
rb_int_cmp(VALUE x, VALUE y)
{
if (FIXNUM_P(x)) {
return fix_cmp(x, y);
}
else if (RB_TYPE_P(x, T_BIGNUM)) {
return rb_big_cmp(x, y);
}
else {
rb_raise(rb_eNotImpError, "need to define `<=>' in %s", rb_obj_classname(x));
}
}
Comparison—Returns -1, 0, or +1 depending on whether int is less than, equal to, or greater than numeric.
This is the basis for the tests in the Comparable module.
nil is returned if the two values are incomparable.