diff options
| author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-10 06:15:02 +0000 |
|---|---|---|
| committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-10 06:15:02 +0000 |
| commit | bec77ef49adfa3192c53f681236b189f02068f8f (patch) | |
| tree | 43110294bfb3bd7cb0924cede0e868110a3c6302 | |
| parent | bcdcc6099a682f5a558d493a5a91c48c694070f0 (diff) | |
| download | ruby-bec77ef49adfa3192c53f681236b189f02068f8f.tar.gz ruby-bec77ef49adfa3192c53f681236b189f02068f8f.tar.xz ruby-bec77ef49adfa3192c53f681236b189f02068f8f.zip | |
* eval.c (rb_f_method_name, rb_f_callee_name): new functions.
new global method `__method__' and `__callee__'.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@10240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | eval.c | 51 |
2 files changed, 56 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Sat Jun 10 15:12:29 2006 NAKAMURA Usaku <usa@ruby-lang.org> + + * eval.c (rb_f_method_name, rb_f_callee_name): new functions. + new global method `__method__' and `__callee__'. + Sat Jun 10 10:13:13 2006 NAKAMURA Usaku <usa@ruby-lang.org> * lib/getoptlong.rb (GetoptLong#set_options): recieve arguments @@ -7691,6 +7691,54 @@ rb_exec_end_proc(void) ruby_safe_level = safe; } +/* + * 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) +{ + struct FRAME* prev = ruby_frame->prev; + if (prev && prev->this_func) { + return ID2SYM(prev->this_func); + } + 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) +{ + struct FRAME* prev = ruby_frame->prev; + if (prev && prev->callee) { + return ID2SYM(prev->callee); + } + else { + return Qnil; + } +} + void Init_eval(void) { @@ -7745,6 +7793,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, "funcall", rb_f_funcall, -1); |
