diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-27 09:53:24 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-27 09:53:24 +0000 |
commit | 8940e3721010e8867242ecf72d23a647304581a1 (patch) | |
tree | 619e121d08b7d2a5a9151dd2cd5e72449eeed879 /eval.c | |
parent | e0bff65092ddd92058994feb33e69195fb216488 (diff) | |
download | ruby-8940e3721010e8867242ecf72d23a647304581a1.tar.gz |
* eval.c (rb_overlay_module, rb_mod_refine): accept a module as the
argument of Module#refine.
* vm_method.c (search_method): if klass is an iclass, lookup the
original module of the iclass in omod in order to allow
refinements of modules.
* test/ruby/test_refinement.rb: add tests for the above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -1030,12 +1030,22 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module) return module; } +static +void check_class_or_module(VALUE obj) +{ + if (!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE)) { + VALUE str = rb_inspect(obj); + rb_raise(rb_eTypeError, "%s is not a class/module", + StringValuePtr(str)); + } +} + void rb_overlay_module(NODE *cref, VALUE klass, VALUE module) { VALUE iclass, c, superclass = klass; - Check_Type(klass, T_CLASS); + check_class_or_module(klass); Check_Type(module, T_MODULE); if (NIL_P(cref->nd_omod)) { cref->nd_omod = rb_hash_new(); @@ -1184,7 +1194,7 @@ rb_mod_refine(VALUE module, VALUE klass) ID id_overlaid_modules, id_refined_class; VALUE overlaid_modules; - Check_Type(klass, T_CLASS); + check_class_or_module(klass); CONST_ID(id_overlaid_modules, "__overlaid_modules__"); overlaid_modules = rb_attr_get(module, id_overlaid_modules); if (NIL_P(overlaid_modules)) { |