diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-08 14:56:08 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-10-08 14:56:08 +0000 |
commit | 1bb89a6dea9e2ec3730713285fba33c197578fb8 (patch) | |
tree | 633b96cdadde1962934a8d4988ab9c626ac70f24 /eval.c | |
parent | e028d3d90572a58f87f4efb6ada3ffdc857d44c7 (diff) |
* eval.c (rb_mod_refinements): new method Module#refinements.
* test/ruby/test_refinement.rb: add new tests for the above changes.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -1226,6 +1226,37 @@ rb_mod_refine(VALUE module, VALUE klass) return mod; } +static int +refinements_i(VALUE key, VALUE value, VALUE arg) +{ + rb_hash_aset(arg, key, value); + return ST_CONTINUE; +} + +/* + * call-seq: + * refinements -> hash + * + * Returns refinements in the receiver as a hash table, whose key is a + * refined class and whose value is a refinement module. + */ + +static VALUE +rb_mod_refinements(VALUE module) +{ + ID id_refinements; + VALUE refinements, result; + + CONST_ID(id_refinements, "__refinements__"); + refinements = rb_attr_get(module, id_refinements); + if (NIL_P(refinements)) { + return rb_hash_new(); + } + result = rb_hash_new(); + rb_hash_foreach(refinements, refinements_i, result); + return result; +} + void rb_obj_call_init(VALUE obj, int argc, VALUE *argv) { @@ -1524,6 +1555,7 @@ Init_eval(void) rb_define_private_method(rb_cModule, "prepend", rb_mod_prepend, -1); rb_define_private_method(rb_cModule, "using", rb_mod_using, 1); rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1); + rb_define_method(rb_cModule, "refinements", rb_mod_refinements, 0); rb_undef_method(rb_cClass, "module_function"); |