diff --git a/ChangeLog b/ChangeLog index f46352d193..6aa8423c07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Mar 20 16:20:49 2007 Yukihiro Matsumoto + + * 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 * lib/set.rb: Revise rdoc. diff --git a/eval.c b/eval.c index 12ab5e992a..53517c25bf 100644 --- a/eval.c +++ b/eval.c @@ -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 nil. + * See also \_\_callee__. + * + */ + +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 nil. + * See also \_\_method__. + * + */ + +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);