diff options
-rw-r--r-- | eval_error.c | 22 | ||||
-rw-r--r-- | eval_intern.h | 1 | ||||
-rw-r--r-- | proc.c | 11 |
3 files changed, 22 insertions, 12 deletions
diff --git a/eval_error.c b/eval_error.c index 401eba8c54..8bcbd39c5e 100644 --- a/eval_error.c +++ b/eval_error.c @@ -208,8 +208,8 @@ ruby_error_print(void) error_print(); } -void -rb_print_undef(VALUE klass, ID id, int scope) +static const char * +method_scope_name(int scope) { const char *v; @@ -219,6 +219,13 @@ rb_print_undef(VALUE klass, ID id, int scope) case NOEX_PRIVATE: v = " private"; break; case NOEX_PROTECTED: v = " protected"; break; } + return v; +} + +void +rb_print_undef(VALUE klass, ID id, int scope) +{ + const char *v = method_scope_name(scope); rb_name_error(id, "undefined%s method `%"PRIsVALUE"' for %s `%"PRIsVALUE"'", v, QUOTE_ID(id), (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", @@ -234,6 +241,17 @@ rb_print_undef_str(VALUE klass, VALUE name) rb_class_name(klass)); } +void +rb_print_inaccessible(VALUE klass, ID id, int scope) +{ + const char *v = method_scope_name(scope); + rb_name_error(id, "method `%s' for %s `% "PRIsVALUE"' is %s", + rb_id2name(id), + (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", + rb_class_name(klass), + v); +} + static int sysexit_status(VALUE err) { diff --git a/eval_intern.h b/eval_intern.h index 163c87c881..c457deb8db 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -238,6 +238,7 @@ NORETURN(void rb_fiber_start(void)); NORETURN(void rb_print_undef(VALUE, ID, int)); NORETURN(void rb_print_undef_str(VALUE, VALUE)); +NORETURN(void rb_print_inaccessible(VALUE, ID, int)); NORETURN(void rb_vm_localjump_error(const char *,VALUE, int)); NORETURN(void rb_vm_jump_tag_but_local_jump(int)); NORETURN(void rb_raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, @@ -1219,16 +1219,7 @@ mnew_from_me(rb_method_entry_t *me, VALUE defined_class, VALUE klass, if (flag == NOEX_UNDEF) { flag = me->flag; if (scope && (flag & NOEX_MASK) != NOEX_PUBLIC) { - const char *v = ""; - switch (flag & NOEX_MASK) { - case NOEX_PRIVATE: v = "private"; break; - case NOEX_PROTECTED: v = "protected"; break; - } - rb_name_error(id, "method `%s' for %s `% "PRIsVALUE"' is %s", - rb_id2name(id), - (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", - rb_class_name(klass), - v); + rb_print_inaccessible(klass, id, flag & NOEX_MASK); } } if (def && def->type == VM_METHOD_TYPE_ZSUPER) { |