diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-20 07:21:37 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-20 07:21:37 +0000 |
commit | edec8b39f95bb6ed0b0e95f248e21beb110ffa34 (patch) | |
tree | 823b6df8b4a70abe68147c3eab082ec1f6f0f29f /eval.c | |
parent | 4503c8daebd2b8c572a313117b5d9c50e824ab14 (diff) | |
download | ruby-edec8b39f95bb6ed0b0e95f248e21beb110ffa34.tar.gz |
* eval.c (rb_f_callee_name): add __method__ and __callee__ again.
__callee__ need to rework to adopt YARV. [ruby-core:10671]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -2828,6 +2828,57 @@ rb_f_local_variables(void) } +/* + * call-seq: + * __method__ => string + * + * Returns the name of the current method as a Symbol. + * If called from inside of an aliased method it will return the original + * nonaliased name. + * If called outside of a method, it returns <code>nil</code>. + * See also <code>\_\_callee__</code>. + * + */ + +static VALUE +rb_f_method_name(void) +{ + ID fname = rb_frame_callee(); + + if (fname) { + return ID2SYM(fname); + } + else { + return Qnil; + } +} + +/* + * call-seq: + * __callee__ => string + * + * Returns the name of the current method as Symbol. + * If called from inside of an aliased method it will return the aliased + * name. + * If called outside of a method, it returns <code>nil</code>. + * See also <code>\_\_method__</code>. + * + */ + +static VALUE +rb_f_callee_name(void) +{ + /* xxx need to get callee name */ + ID callee = rb_frame_callee(); + + if (callee) { + return ID2SYM(callee); + } + else { + return Qnil; + } +} + void Init_eval(void) { @@ -2877,6 +2928,9 @@ Init_eval(void) rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */ rb_define_global_function("local_variables", rb_f_local_variables, 0); + rb_define_global_function("__method__", rb_f_method_name, 0); + rb_define_global_function("__callee__", rb_f_callee_name, 0); + rb_define_method(rb_cBasicObject, "send", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send", rb_f_send, -1); |