diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-13 17:38:12 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-13 17:38:12 +0000 |
commit | 25f5dd6799bbacc9f61d60b87b70ea6e6d815c20 (patch) | |
tree | 7570ecd30255961f8eb7d50bf15b41d0e0715f25 /vm.c | |
parent | dd4cec36ca0229e5dcc45393f59f2633d2e350bf (diff) |
* vm.c (vm_define_method): do not use current CREF immediately,
but check CREF in environment or methods. Methods defined in methods
should be public.
[Bug #11571]
* vm_method.c (rb_scope_module_func_check): check CREF in env or me.
if CREF is contained by `me', then return FALSE.
* test/ruby/test_method.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -2340,22 +2340,25 @@ static void vm_define_method(rb_thread_t *th, VALUE obj, ID id, VALUE iseqval, rb_num_t is_singleton, rb_cref_t *cref) { - VALUE klass = CREF_CLASS(cref); - const rb_scope_visibility_t *scope_visi = CREF_SCOPE_VISI(cref); - rb_method_visibility_t visi = scope_visi->method_visi; + VALUE klass; + rb_method_visibility_t visi; - if (NIL_P(klass)) { - rb_raise(rb_eTypeError, "no class/module to add method"); + if (!is_singleton) { + klass = obj; + visi = rb_scope_visibility_get(); } - - if (is_singleton) { + else { /* singleton */ klass = rb_singleton_class(obj); /* class and frozen checked in this API */ visi = METHOD_VISI_PUBLIC; } + if (NIL_P(klass)) { + rb_raise(rb_eTypeError, "no class/module to add method"); + } + rb_add_method_iseq(klass, id, (const rb_iseq_t *)iseqval, cref, visi); - if (!is_singleton && scope_visi->module_func) { + if (!is_singleton && rb_scope_module_func_check()) { klass = rb_singleton_class(klass); rb_add_method_iseq(klass, id, (const rb_iseq_t *)iseqval, cref, METHOD_VISI_PUBLIC); } |