inspect()
public
Returns the representation of sym as a symbol literal.
:fred.inspect
Show source
static VALUE
sym_inspect(VALUE sym)
{
VALUE str;
const char *ptr;
long len;
ID id = SYM2ID(sym);
char *dest;
sym = rb_id2str(id);
if (!rb_str_symname_p(sym)) {
str = rb_str_inspect(sym);
len = RSTRING_LEN(str);
rb_str_resize(str, len + 1);
dest = RSTRING_PTR(str);
memmove(dest + 1, dest, len);
dest[0] = ':';
}
else {
rb_encoding *enc = STR_ENC_GET(sym);
ptr = RSTRING_PTR(sym);
len = RSTRING_LEN(sym);
str = rb_enc_str_new(0, len + 1, enc);
dest = RSTRING_PTR(str);
dest[0] = ':';
memcpy(dest + 1, ptr, len);
}
return str;
}