/*
* call-seq:
* sym.inspect => string
*
* Returns the representation of <i>sym</i> as a symbol literal.
*
* :fred.inspect #=> ":fred"
*/
static VALUE
sym_inspect(VALUE sym)
{
VALUE str, klass = Qundef;
ID id = SYM2ID(sym);
rb_encoding *enc;
sym = rb_id2str(id);
enc = STR_ENC_GET(sym);
str = rb_enc_str_new(0, RSTRING_LEN(sym)+1, enc);
RSTRING_PTR(str)[0] = ':';
memcpy(RSTRING_PTR(str)+1, RSTRING_PTR(sym), RSTRING_LEN(sym));
if (RSTRING_LEN(sym) != strlen(RSTRING_PTR(sym)) ||
!rb_enc_symname_p(RSTRING_PTR(sym), enc)) {
str = rb_str_inspect(str);
strncpy(RSTRING_PTR(str), ":\"", 2);
}
if (klass != Qundef) {
rb_str_cat2(str, "/");
rb_str_append(str, rb_inspect(klass));
}
return str;
}