Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Returns the representation of sym as a symbol literal.
:fred.inspect   #=> ":fred"
 
               static VALUE
sym_inspect(VALUE sym)
{
    VALUE str = rb_sym2str(sym);
    const char *ptr;
    long len;
    char *dest;

    if (!rb_str_symname_p(str)) {
        str = rb_str_inspect(str);
        len = RSTRING_LEN(str);
        rb_str_resize(str, len + 1);
        dest = RSTRING_PTR(str);
        memmove(dest + 1, dest, len);
    }
    else {
        rb_encoding *enc = STR_ENC_GET(str);
        RSTRING_GETMEM(str, ptr, len);
        str = rb_enc_str_new(0, len + 1, enc);
        dest = RSTRING_PTR(str);
        memcpy(dest + 1, ptr, len);
    }
    dest[0] = ':';
    return str;
}
            

Was this page useful?