public Method

Integer.chr

int.chr     string

Returns a string containing the ASCII character represented by the receiver’s value.

65.chr    #=> "A"
?a.chr    #=> "a"
230.chr   #=> "\346"

Source Code

/*
*  call-seq:
*     int.chr    => string
*  
*  Returns a string containing the ASCII character represented by the
*  receiver's value.
*     
*     65.chr    #=> "A"
*     ?a.chr    #=> "a"
*     230.chr   #=> "\346"
*/

static VALUE
int_chr(num)
   VALUE num;
{
   char c;
   long i = NUM2LONG(num);

   if (i < 0 || 0xff < i)
       rb_raise(rb_eRangeError, "%ld out of char range", i);
   c = i;
   return rb_str_new(&c, 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.