aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-23 11:46:33 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-23 11:46:33 +0000
commitb166d4bc7c9710e1b6184659d2f51710228998f6 (patch)
tree97d7228c670ed87e3c39b77f7d96b97503bd170d /eval.c
parentf32fba70c5984f990503bdc5b3aac245117de4d6 (diff)
downloadruby-b166d4bc7c9710e1b6184659d2f51710228998f6.tar.gz
* eval.c (rb_mod_refine): refine modules as well.
[ruby-core:76199] [Feature #12534] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/eval.c b/eval.c
index 1baf914a3a..5f5da2881a 100644
--- a/eval.c
+++ b/eval.c
@@ -1092,6 +1092,16 @@ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
return module;
}
+static void
+ensure_class_or_module(VALUE obj)
+{
+ if (!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE)) {
+ rb_raise(rb_eTypeError,
+ "wrong argument type %"PRIsVALUE" (expected Class or Module)",
+ rb_obj_class(obj));
+ }
+}
+
static VALUE
hidden_identity_hash_new(void)
{
@@ -1106,7 +1116,7 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
{
VALUE iclass, c, superclass = klass;
- Check_Type(klass, T_CLASS);
+ ensure_class_or_module(klass);
Check_Type(module, T_MODULE);
if (NIL_P(CREF_REFINEMENTS(cref))) {
CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
@@ -1231,11 +1241,11 @@ add_activated_refinement(VALUE activated_refinements,
/*
* call-seq:
- * refine(klass) { block } -> module
+ * refine(mod) { block } -> module
*
- * Refine <i>klass</i> in the receiver.
+ * Refine <i>mod</i> in the receiver.
*
- * Returns an overlaid module.
+ * Returns a module, where refined methods are defined.
*/
static VALUE
@@ -1255,7 +1265,7 @@ rb_mod_refine(VALUE module, VALUE klass)
rb_raise(rb_eArgError, "can't pass a Proc as a block to Module#refine");
}
- Check_Type(klass, T_CLASS);
+ ensure_class_or_module(klass);
CONST_ID(id_refinements, "__refinements__");
refinements = rb_attr_get(module, id_refinements);
if (NIL_P(refinements)) {