diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-02-27 04:50:30 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-02-27 04:50:30 +0000 |
commit | bf95c21de1a5a91a969b2677504da262c8cb1c21 (patch) | |
tree | 9c8fcdf87cfc279f6dd3348de22d1bc74f26f48a /eval.c | |
parent | a08335cc90e1e6d559b0ead207c42babe424ec57 (diff) |
* eval.c (rb_f_missing): NoMethod error messages for true, false,
nil must respond visibility like for other objects.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@2144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 47 |
1 files changed, 24 insertions, 23 deletions
@@ -4082,7 +4082,7 @@ rb_f_missing(argc, argv, obj) VALUE *argv; VALUE obj; { - ID id; + ID id, noclass; volatile VALUE d = 0; char *format = 0; char *desc = ""; @@ -4096,17 +4096,16 @@ rb_f_missing(argc, argv, obj) rb_stack_check(); id = SYM2ID(argv[0]); - argc--; argv++; switch (TYPE(obj)) { case T_NIL: - format = "undefined method `%s' for nil"; + desc = "nil"; break; case T_TRUE: - format = "undefined method `%s' for true"; + desc = "true"; break; case T_FALSE: - format = "undefined method `%s' for false"; + desc = "false"; break; case T_OBJECT: d = rb_any_to_s(obj); @@ -4116,36 +4115,38 @@ rb_f_missing(argc, argv, obj) break; } if (d) { - if (last_call_status & CSTAT_PRIV) { - format = "private method `%s' called for %s%s%s"; - } - if (last_call_status & CSTAT_PROT) { - format = "protected method `%s' called for %s%s%s"; - } - else if (last_call_status & CSTAT_VCALL) { - const char *mname = rb_id2name(id); - - if (('a' <= mname[0] && mname[0] <= 'z') || mname[0] == '_') { - format = "undefined local variable or method `%s' for %s%s%s"; - } - } - if (!format) { - format = "undefined method `%s' for %s%s%s"; - } if (RSTRING(d)->len > 65) { d = rb_any_to_s(obj); } desc = RSTRING(d)->ptr; } + if (last_call_status & CSTAT_PRIV) { + format = "private method `%s' called for %s%s%s"; + } + if (last_call_status & CSTAT_PROT) { + format = "protected method `%s' called for %s%s%s"; + } + else if (last_call_status & CSTAT_VCALL) { + const char *mname = rb_id2name(id); + + if (('a' <= mname[0] && mname[0] <= 'z') || mname[0] == '_') { + format = "undefined local variable or method `%s' for %s%s%s"; + } + } + if (!format) { + format = "undefined method `%s' for %s%s%s"; + } + ruby_sourcefile = file; ruby_sourceline = line; PUSH_FRAME(); /* fake frame */ *ruby_frame = *_frame.prev->prev; + noclass = (!d || desc[0]=='#'); rb_raise(rb_eNameError, format, rb_id2name(id), - desc, desc[0]=='#'?"":":", - desc[0]=='#'?"":rb_class2name(CLASS_OF(obj))); + desc, noclass ? "" : ":", + noclass ? "" : rb_class2name(CLASS_OF(obj))); POP_FRAME(); return Qnil; /* not reached */ |