* eval.c (rb_f_method_name, rb_f_callee_name): new functions.

new global method `__method__' and `__callee__'.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2006-06-10 06:15:02 +00:00
Родитель 8686ee1861
Коммит d1a664a464
2 изменённых файлов: 56 добавлений и 0 удалений

Просмотреть файл

@ -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

51
eval.c
Просмотреть файл

@ -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);