diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-29 02:21:27 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-29 02:21:27 +0000 |
commit | 0954607864bcdd81ea5f3dd2ea52f638f2f32e47 (patch) | |
tree | bf798ae8e5bc1a3e2ebdb7ded0bf8555701b8534 /vm_insnhelper.c | |
parent | 039e2a35c2e410cf1679cf10b492112cc67931a9 (diff) |
* vm_insnhelper.c (rb_vm_using_modules): use using_modules before
klass to fix method lookup order, and use klass even if klass is
not a module to make refinements in class_eval invoked on classes
work.
* eval.c (rb_using_module): accept a class as the second argument.
* eval.c (rb_mod_using, f_using): raise a TypeError if the argument
is not a module.
* test/ruby/test_refinement.rb: add new tests for the above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r-- | vm_insnhelper.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c index f134487107..60547d049a 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1830,27 +1830,22 @@ rb_vm_using_modules(NODE *cref, VALUE klass) ID id_using_modules; VALUE using_modules; + if (NIL_P(klass)) return; CONST_ID(id_using_modules, "__using_modules__"); using_modules = rb_attr_get(klass, id_using_modules); - switch (TYPE(klass)) { - case T_CLASS: - if (NIL_P(using_modules)) { - VALUE super = rb_class_real(RCLASS_SUPER(klass)); - using_modules = rb_attr_get(super, id_using_modules); - if (!NIL_P(using_modules)) { - using_modules = rb_hash_dup(using_modules); - rb_ivar_set(klass, id_using_modules, using_modules); - } + if (NIL_P(using_modules) && BUILTIN_TYPE(klass) == T_CLASS) { + VALUE super = rb_class_real(RCLASS_SUPER(klass)); + using_modules = rb_attr_get(super, id_using_modules); + if (!NIL_P(using_modules)) { + using_modules = rb_hash_dup(using_modules); + rb_ivar_set(klass, id_using_modules, using_modules); } - break; - case T_MODULE: - rb_using_module(cref, klass); - break; } if (!NIL_P(using_modules)) { rb_hash_foreach(using_modules, vm_using_module_i, (VALUE) cref); } + rb_using_module(cref, klass); } static VALUE |