public Method

Fixnum.<=>(p1)

fix <→ numeric     -1, 0, +1

Comparison—Returns -1, 0, or +1 depending on whether fix is less than, equal to, or greater than numeric. This is the basis for the tests in Comparable.

Source Code

/*
*  call-seq:
*     fix <=> numeric    => -1, 0, +1
*  
*  Comparison---Returns -1, 0, or +1 depending on whether <i>fix</i> is
*  less than, equal to, or greater than <i>numeric</i>. This is the
*  basis for the tests in <code>Comparable</code>.
*/

static VALUE
fix_cmp(x, y)
   VALUE x, y;
{
   if (x == y) return INT2FIX(0);
   if (FIXNUM_P(y)) {
       long a = FIX2LONG(x), b = FIX2LONG(y);

       if (a > b) return INT2FIX(1);
       return INT2FIX(-1);
   }
   else {
       return rb_num_coerce_cmp(x, y);
   }
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.