to_str()
public
Hide source
static VALUE name_err_mesg_to_str(VALUE obj) { VALUE *ptr, mesg; TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr); mesg = ptr[NAME_ERR_MESG__MESG]; if (NIL_P(mesg)) return Qnil; else { struct RString s_str, d_str; VALUE c, s, d = 0, args[4]; int state = 0, singleton = 0; rb_encoding *usascii = rb_usascii_encoding(); #define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii) obj = ptr[NAME_ERR_MESG__RECV]; switch (obj) { case Qnil: d = FAKE_CSTR(&d_str, "nil"); break; case Qtrue: d = FAKE_CSTR(&d_str, "true"); break; case Qfalse: d = FAKE_CSTR(&d_str, "false"); break; default: d = rb_protect(rb_inspect, obj, &state); if (state) rb_set_errinfo(Qnil); if (NIL_P(d) || RSTRING_LEN(d) > 65) { d = rb_any_to_s(obj); } singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#'); d = QUOTE(d); break; } if (!singleton) { s = FAKE_CSTR(&s_str, ":"); c = rb_class_name(CLASS_OF(obj)); } else { c = s = FAKE_CSTR(&s_str, ""); } args[0] = QUOTE(rb_obj_as_string(ptr[NAME_ERR_MESG__NAME])); args[1] = d; args[2] = s; args[3] = c; mesg = rb_str_format(4, args, mesg); } return mesg; }