method
to_str
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[0]; if (NIL_P(mesg)) return Qnil; else { const char *desc = 0; VALUE d = 0, args[NAME_ERR_MESG_COUNT]; int state = 0; obj = ptr[1]; switch (TYPE(obj)) { case T_NIL: desc = "nil"; break; case T_TRUE: desc = "true"; break; case T_FALSE: desc = "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); } desc = RSTRING_PTR(d); break; } if (desc && desc[0] != '#') { d = d ? rb_str_dup(d) : rb_str_new2(desc); rb_str_cat2(d, ":"); rb_str_cat2(d, rb_obj_classname(obj)); } args[0] = mesg; args[1] = ptr[2]; args[2] = d; mesg = rb_f_sprintf(NAME_ERR_MESG_COUNT, args); } OBJ_INFECT(mesg, obj); return mesg; }