ruby-changes:4630
From: ko1@a...
Date: Mon, 21 Apr 2008 17:21:08 +0900 (JST)
Subject: [ruby-changes:4630] knu - Ruby:r16124 (ruby_1_8): * eval.c (rb_f_method_name): New gloval function: __method__;
knu 2008-04-21 17:20:52 +0900 (Mon, 21 Apr 2008) New Revision: 16124 Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/NEWS branches/ruby_1_8/eval.c branches/ruby_1_8/intern.h Log: * eval.c (rb_f_method_name): New gloval function: __method__; backported from matzruby / 1.9. * eval.c (rb_frame_this_func), intern.h: New internal function. * intern.h (RETURN_ENUMERATOR): Use rb_frame_this_func() instead of rb_frame_last_func(), to accommodate the behavior to that of 1.9. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/intern.h?r1=16124&r2=16123&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16124&r2=16123&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16124&r2=16123&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/eval.c?r1=16124&r2=16123&diff_format=u Index: ruby_1_8/intern.h =================================================================== --- ruby_1_8/intern.h (revision 16123) +++ ruby_1_8/intern.h (revision 16124) @@ -133,7 +133,7 @@ VALUE rb_enumeratorize _((VALUE, VALUE, int, VALUE *)); #define RETURN_ENUMERATOR(obj, argc, argv) do { \ if (!rb_block_given_p()) \ - return rb_enumeratorize(obj, ID2SYM(rb_frame_last_func()), \ + return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()), \ argc, argv); \ } while (0) /* error.c */ @@ -180,6 +180,7 @@ VALUE rb_apply _((VALUE, ID, VALUE)); void rb_backtrace _((void)); ID rb_frame_last_func _((void)); +ID rb_frame_this_func _((void)); VALUE rb_obj_instance_eval _((int, VALUE*, VALUE)); VALUE rb_mod_module_eval _((int, VALUE*, VALUE)); void rb_load _((VALUE, int)); Index: ruby_1_8/NEWS =================================================================== --- ruby_1_8/NEWS (revision 16123) +++ ruby_1_8/NEWS (revision 16124) @@ -232,6 +232,11 @@ Return an enumerator if no block is given. + * __method__ + + New global function that returns the name of the current method as + a Symbol. + * enumerator * Enumerator is now a built-in module. The #next and #rewind Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 16123) +++ ruby_1_8/ChangeLog (revision 16124) @@ -1,3 +1,21 @@ +Mon Apr 21 17:19:52 2008 Akinori MUSHA <knu@i...> + + * eval.c (rb_f_method_name): New gloval function: __method__; + backported from matzruby / 1.9. + + * eval.c (rb_frame_this_func), intern.h: New internal function. + + * intern.h (RETURN_ENUMERATOR): Use rb_frame_this_func() instead + of rb_frame_last_func(), to accommodate the behavior to that of + 1.9. + +Mon Apr 21 15:54:48 2008 Yukihiro Matsumoto <matz@r...> + + * lib/tempfile.rb (Tempfile::_close): check @data before modifying + it; backported from 1.9. [ruby-dev:34094] + + * lib/tempfile.rb (Tempfile::close): clear @data and @tmpname. + Mon Apr 21 10:17:17 2008 NAKAMURA Usaku <usa@r...> * time.c: should include <errno.h> to refer errno. @@ -113,13 +131,6 @@ test/uri/test_ftp.rb, test/uri/test_generic.rb: backported from 1.9. [ruby-dev:31318] -Wed Apr 16 14:22:42 2008 Yukihiro Matsumoto <matz@r...> - - * lib/tempfile.rb (Tempfile::_close): check @data before modifying - it backported from 1.9. [ruby-dev:34094] - - * lib/tempfile.rb (Tempfile::close): clear @data and @tmpname. - Wed Apr 16 06:03:45 2008 Akinori MUSHA <knu@i...> * test/ruby/test_settracefunc.rb (TestSetTraceFunc#test_event): Index: ruby_1_8/eval.c =================================================================== --- ruby_1_8/eval.c (revision 16123) +++ ruby_1_8/eval.c (revision 16124) @@ -6407,6 +6407,12 @@ return ruby_frame->last_func; } +ID +rb_frame_this_func() +{ + return ruby_frame->orig_func; +} + static NODE* compile(src, file, line) VALUE src; @@ -7990,6 +7996,37 @@ ruby_safe_level = safe; } +/* + * call-seq: + * __method__ => symbol + * + * 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>. + * + * def foo + * __method__ + * end + * alias bar foo + * + * foo # => :foo + * bar # => :foo + * + */ + +static VALUE +rb_f_method_name() +{ + struct FRAME* prev = ruby_frame->prev; + if (prev && prev->orig_func) { + return ID2SYM(prev->orig_func); + } + else { + return Qnil; + } +} + void Init_eval() { @@ -8046,6 +8083,8 @@ 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_method(rb_mKernel, "send", rb_f_send, -1); rb_define_method(rb_mKernel, "__send__", rb_f_send, -1); rb_define_method(rb_mKernel, "instance_eval", rb_obj_instance_eval, -1); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/