mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Stop using receiver#inspect for "undefined method" errors
``` 42.time #=> undefined method `time' for object Integer (NoMethodError) class Foo privatee #=> undefined local variable or method 'privatee' for class Foo (NoMethodError) end s = "" def s.foo = nil s.bar #=> undefined method `bar' for extended object String (NoMethodError) ``` [Feature #18285]
This commit is contained in:
parent
5c0298bf18
commit
e7b8d32e16
Notes:
git
2023-02-20 01:33:36 +00:00
2 changed files with 57 additions and 24 deletions
10
vm_eval.c
10
vm_eval.c
|
@ -933,7 +933,7 @@ rb_make_no_method_exception(VALUE exc, VALUE format, VALUE obj,
|
|||
VALUE name = argv[0];
|
||||
|
||||
if (!format) {
|
||||
format = rb_fstring_lit("undefined method `%s' for %s%s%s");
|
||||
format = rb_fstring_lit("undefined method `%1$s' for %3$s%4$s");
|
||||
}
|
||||
if (exc == rb_eNoMethodError) {
|
||||
VALUE args = rb_ary_new4(argc - 1, argv + 1);
|
||||
|
@ -965,17 +965,17 @@ raise_method_missing(rb_execution_context_t *ec, int argc, const VALUE *argv, VA
|
|||
stack_check(ec);
|
||||
|
||||
if (last_call_status & MISSING_PRIVATE) {
|
||||
format = rb_fstring_lit("private method `%s' called for %s%s%s");
|
||||
format = rb_fstring_lit("private method `%1$s' called for %3$s%4$s");
|
||||
}
|
||||
else if (last_call_status & MISSING_PROTECTED) {
|
||||
format = rb_fstring_lit("protected method `%s' called for %s%s%s");
|
||||
format = rb_fstring_lit("protected method `%1$s' called for %3$s%4$s");
|
||||
}
|
||||
else if (last_call_status & MISSING_VCALL) {
|
||||
format = rb_fstring_lit("undefined local variable or method `%s' for %s%s%s");
|
||||
format = rb_fstring_lit("undefined local variable or method `%1$s' for %3$s%4$s");
|
||||
exc = rb_eNameError;
|
||||
}
|
||||
else if (last_call_status & MISSING_SUPER) {
|
||||
format = rb_fstring_lit("super: no superclass method `%s' for %s%s%s");
|
||||
format = rb_fstring_lit("super: no superclass method `%1$s' for %3$s%4$s");
|
||||
}
|
||||
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue