ruby-changes:5135
From: knu <ko1@a...>
Date: Tue, 27 May 2008 16:03:33 +0900 (JST)
Subject: [ruby-changes:5135] Ruby:r16630 (ruby_1_8): * eval.c (rb_mod_module_exec, Init_eval): Add
knu 2008-05-27 16:03:21 +0900 (Tue, 27 May 2008) New Revision: 16630 Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/NEWS branches/ruby_1_8/eval.c Log: * eval.c (rb_mod_module_exec, Init_eval): Add Module#{module_exec,class_exec}. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16630&r2=16629&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16630&r2=16629&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/eval.c?r1=16630&r2=16629&diff_format=u Index: ruby_1_8/NEWS =================================================================== --- ruby_1_8/NEWS (revision 16629) +++ ruby_1_8/NEWS (revision 16630) @@ -193,9 +193,11 @@ New methods. - * Method#receiver + * Method#class_exec + * Method#module_exec * Method#name * Method#owner + * Method#receiver * UnboundMethod#name * UnboundMethod#owner Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 16629) +++ ruby_1_8/ChangeLog (revision 16630) @@ -1,3 +1,8 @@ +Tue May 27 16:02:58 2008 Akinori MUSHA <knu@i...> + + * eval.c (rb_mod_module_exec, Init_eval): Add + Module#{module_exec,class_exec}. + Tue May 27 15:36:37 2008 Akinori MUSHA <knu@i...> * io.c (rb_io_each_char, argf_each_char, Init_IO): Index: ruby_1_8/eval.c =================================================================== --- ruby_1_8/eval.c (revision 16629) +++ ruby_1_8/eval.c (revision 16630) @@ -6918,6 +6918,35 @@ return specific_eval(argc, argv, mod, mod); } +/* + * call-seq: + * mod.module_exec(arg...) {|var...| block } => obj + * mod.class_exec(arg...) {|var...| block } => obj + * + * Evaluates the given block in the context of the class/module. + * The method defined in the block will belong to the receiver. + * + * class Thing + * end + * Thing.class_exec{ + * def hello() "Hello there!" end + * } + * puts Thing.new.hello() + * + * <em>produces:</em> + * + * Hello there! + */ + +VALUE +rb_mod_module_exec(argc, argv, mod) + int argc; + VALUE *argv; + VALUE mod; +{ + return yield_under(mod, mod, rb_ary_new4(argc, argv)); +} + VALUE rb_load_path; NORETURN(static void load_failed _((VALUE))); @@ -8187,7 +8216,9 @@ rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1); + rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1); rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1); + rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1); rb_undef_method(rb_cClass, "module_function"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/