diff options
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); |