diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-26 16:05:35 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-26 16:05:35 +0000 |
commit | 8603c5934a4e613cdb07b04a1ce86fb1f21fdbd5 (patch) | |
tree | 44fdf5f0b148df430c6c0d667ef8139e73ed9b50 /vm_method.c | |
parent | 298349d03bcdb6c25420d9a92265816d59892a1f (diff) | |
download | ruby-8603c5934a4e613cdb07b04a1ce86fb1f21fdbd5.tar.gz |
* eval_error.c (rb_print_undef_str): new function to raise
NameError for undefined method.
* load.c (rb_mod_autoload_p), object.c (rb_mod_const_get),
variable.c (rb_f_untrace_var, set_const_visibility), vm_method.c
(rb_mod_{remove,undef,alias}_method, set_method_visibility):
remove inadvertent symbol creation. based on the first patch by
Jeremy Evans at [ruby-core:38447]. [Feature #5089]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/vm_method.c b/vm_method.c index d7d18cf4fa..4f18be2b94 100644 --- a/vm_method.c +++ b/vm_method.c @@ -485,7 +485,13 @@ rb_mod_remove_method(int argc, VALUE *argv, VALUE mod) int i; for (i = 0; i < argc; i++) { - remove_method(mod, rb_to_id(argv[i])); + VALUE v = argv[i]; + ID id = rb_check_id(&v); + if (!id) { + rb_name_error_str(v, "method `%s' not defined in %s", + RSTRING_PTR(v), rb_class2name(mod)); + } + remove_method(mod, id); } return mod; } @@ -693,7 +699,12 @@ rb_mod_undef_method(int argc, VALUE *argv, VALUE mod) { int i; for (i = 0; i < argc; i++) { - rb_undef(mod, rb_to_id(argv[i])); + VALUE v = argv[i]; + ID id = rb_check_id(&v); + if (!id) { + rb_method_name_error(mod, v); + } + rb_undef(mod, id); } return mod; } @@ -952,7 +963,11 @@ rb_alias(VALUE klass, ID name, ID def) static VALUE rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname) { - rb_alias(mod, rb_to_id(newname), rb_to_id(oldname)); + ID oldid = rb_check_id(&oldname); + if (!oldid) { + rb_print_undef_str(mod, oldname); + } + rb_alias(mod, rb_to_id(newname), oldid); return mod; } @@ -971,7 +986,12 @@ set_method_visibility(VALUE self, int argc, VALUE *argv, rb_method_flag_t ex) int i; secure_visibility(self); for (i = 0; i < argc; i++) { - rb_export_method(self, rb_to_id(argv[i]), ex); + VALUE v = argv[i]; + ID id = rb_check_id(&v); + if (!id) { + rb_print_undef_str(self, v); + } + rb_export_method(self, id, ex); } rb_clear_cache_by_class(self); } |