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 | 4b2f285f3a8ac7a4db0acf3598b55b8bab0ae655 (patch) | |
tree | 823b6df8b4a70abe68147c3eab082ec1f6f0f29f | |
parent | 5ce464e7141aac7e59a6cf79002723ceff328ecc (diff) | |
download | ruby-4b2f285f3a8ac7a4db0acf3598b55b8bab0ae655.tar.gz ruby-4b2f285f3a8ac7a4db0acf3598b55b8bab0ae655.tar.xz ruby-4b2f285f3a8ac7a4db0acf3598b55b8bab0ae655.zip |
* eval.c (rb_f_callee_name): add __method__ and __callee__ again.
__callee__ need to rework to adopt YARV. [ruby-core:10671]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | eval.c | 54 |
2 files changed, 59 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Tue Mar 20 16:20:49 2007 Yukihiro Matsumoto <matz@ruby-lang.org> + + * eval.c (rb_f_callee_name): add __method__ and __callee__ again. + __callee__ need to rework to adopt YARV. [ruby-core:10671] + Tue Mar 20 11:09:00 2007 Akinori MUSHA <knu@iDaemons.org> * lib/set.rb: Revise rdoc. @@ -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); |