diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-01 23:24:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-01 23:24:33 +0000 |
commit | 499b5a9197f68e14873e641b737aea40a0f8bc5a (patch) | |
tree | ad6295bdf751500f6577856d881bd9c27824259a /proc.c | |
parent | 603fcafdc33ea5aed55240020e7287597b6b2e01 (diff) | |
download | ruby-499b5a9197f68e14873e641b737aea40a0f8bc5a.tar.gz |
proc.c: main.define_method
* proc.c (top_define_method): new method, main.define_method.
[ruby-core:45715] [Feature #6609]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1449,6 +1449,30 @@ rb_obj_define_method(int argc, VALUE *argv, VALUE obj) } /* + * define_method(symbol, method) -> new_method + * define_method(symbol) { block } -> proc + * + * Defines a global function by _method_ or the block. + */ + +static VALUE +top_define_method(int argc, VALUE *argv, VALUE obj) +{ + rb_thread_t *th = GET_THREAD(); + VALUE klass; + + rb_secure(4); + klass = th->top_wrapper; + if (klass) { + rb_warning("main.define_method in the wrapped load is effective only in wrapper module"); + } + else { + klass = rb_cObject; + } + return rb_mod_define_method(argc, argv, klass); +} + +/* * call-seq: * method.clone -> new_method * @@ -2290,6 +2314,8 @@ Init_Proc(void) /* Kernel */ rb_define_method(rb_mKernel, "define_singleton_method", rb_obj_define_method, -1); + + rb_define_singleton_method(rb_vm_top_self(), "define_method", top_define_method, -1); } /* |