summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-27 09:53:24 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-27 09:53:24 +0000
commit8940e3721010e8867242ecf72d23a647304581a1 (patch)
tree619e121d08b7d2a5a9151dd2cd5e72449eeed879 /eval.c
parente0bff65092ddd92058994feb33e69195fb216488 (diff)
* 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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 9630ca2621..4d27a8ec6b 100644
--- a/eval.c
+++ b/eval.c
@@ -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)) {