From b166d4bc7c9710e1b6184659d2f51710228998f6 Mon Sep 17 00:00:00 2001 From: shugo Date: Fri, 23 Sep 2016 11:46:33 +0000 Subject: * 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 --- eval.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'eval.c') 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 klass in the receiver. + * Refine mod 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)) { -- cgit v1.2.3