public Method

Integer.succ

int.next     integer
int.succ     integer

Returns the Integer equal to int + 1.

1.next      #=> 2
(-1).next   #=> 0

Source Code

/*
*  call-seq:
*     int.next    => integer
*     int.succ    => integer
*  
*  Returns the <code>Integer</code> equal to <i>int</i> + 1.
*     
*     1.next      #=> 2
*     (-1).next   #=> 0
*/

static VALUE
int_succ(num)
   VALUE num;
{
   if (FIXNUM_P(num)) {
       long i = FIX2LONG(num) + 1;
       return LONG2NUM(i);
   }
   return rb_funcall(num, '+', 1, INT2FIX(1));
}
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.