public Method

Fixnum.to_sym

fix.to_sym  aSymbol

Returns the symbol whose integer value is fix. See also Fixnum#id2name.

fred = :fred.to_i
fred.id2name   #=> "fred"
fred.to_sym    #=> :fred

Source Code

/*
*  call-seq:
*     fix.to_sym -> aSymbol
*  
*  Returns the symbol whose integer value is <i>fix</i>. See also
*  <code>Fixnum#id2name</code>.
*     
*     fred = :fred.to_i
*     fred.id2name   #=> "fred"
*     fred.to_sym    #=> :fred
*/

static VALUE
fix_to_sym(fix)
   VALUE fix;
{
   ID id = FIX2UINT(fix);

   if (rb_id2name(id)) {
       return ID2SYM(id);
   }
   return Qnil;
}
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.