1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

error.c: separate class names

* error.c (name_err_mesg_to_str): separate class names from the
  receiver description.
* vm_eval.c (make_no_method_exception, raise_method_missing): add
  format specifiers for class names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-10-23 12:10:40 +00:00
parent e3b0788378
commit 5bf61f4540
3 changed files with 31 additions and 20 deletions

View file

@ -1,3 +1,11 @@
Fri Oct 23 21:10:37 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (name_err_mesg_to_str): separate class names from the
receiver description.
* vm_eval.c (make_no_method_exception, raise_method_missing): add
format specifiers for class names.
Fri Oct 23 18:10:32 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* .gitignore: ignored environmantal wrapper files.

33
error.c
View file

@ -1219,20 +1219,19 @@ name_err_mesg_to_str(VALUE obj)
mesg = ptr[NAME_ERR_MESG__MESG];
if (NIL_P(mesg)) return Qnil;
else {
const char *desc = 0;
VALUE d = 0, args[NAME_ERR_MESG_COUNT];
int state = 0;
VALUE c, s, d = 0, args[4];
int state = 0, singleton = 0;
obj = ptr[NAME_ERR_MESG__RECV];
switch (obj) {
case Qnil:
desc = "nil";
d = rb_fstring_cstr("nil");
break;
case Qtrue:
desc = "true";
d = rb_fstring_cstr("true");
break;
case Qfalse:
desc = "false";
d = rb_fstring_cstr("false");
break;
default:
d = rb_protect(rb_inspect, obj, &state);
@ -1241,18 +1240,22 @@ name_err_mesg_to_str(VALUE obj)
if (NIL_P(d) || RSTRING_LEN(d) > 65) {
d = rb_any_to_s(obj);
}
desc = RSTRING_PTR(d);
singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#');
d = QUOTE(d);
break;
}
if (desc && desc[0] != '#') {
d = d ? rb_str_dup(d) : rb_str_new2(desc);
rb_str_cat2(d, ":");
rb_str_append(d, rb_class_name(CLASS_OF(obj)));
if (!singleton) {
s = rb_fstring_cstr(":");
c = rb_class_name(CLASS_OF(obj));
}
args[0] = mesg;
args[1] = ptr[NAME_ERR_MESG__NAME];
args[2] = d;
mesg = rb_f_sprintf(NAME_ERR_MESG_COUNT, args);
else {
c = s = rb_fstring_cstr("");
}
args[0] = ptr[NAME_ERR_MESG__NAME];
args[1] = d;
args[2] = s;
args[3] = c;
mesg = rb_str_format(4, args, mesg);
}
return mesg;
}

View file

@ -677,7 +677,7 @@ make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, con
VALUE args[3];
if (!format) {
format = "undefined method `%s' for %s";
format = "undefined method `%s' for %s%s%s";
}
args[n++] = rb_name_err_mesg_new(rb_str_new_cstr(format), obj, argv[0]);
args[n++] = argv[0];
@ -706,17 +706,17 @@ raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj,
stack_check();
if (last_call_status & MISSING_PRIVATE) {
format = "private method `%s' called for %s";
format = "private method `%s' called for %s%s%s";
}
else if (last_call_status & MISSING_PROTECTED) {
format = "protected method `%s' called for %s";
format = "protected method `%s' called for %s%s%s";
}
else if (last_call_status & MISSING_VCALL) {
format = "undefined local variable or method `%s' for %s";
format = "undefined local variable or method `%s' for %s%s%s";
exc = rb_eNameError;
}
else if (last_call_status & MISSING_SUPER) {
format = "super: no superclass method `%s' for %s";
format = "super: no superclass method `%s' for %s%s%s";
}
{