ruby-changes:11581
From: yugui <ko1@a...>
Date: Sun, 19 Apr 2009 22:34:07 +0900 (JST)
Subject: [ruby-changes:11581] Ruby:r23218 (ruby_1_9_1): merges r22990 from trunk into ruby_1_9_1.
yugui 2009-04-19 22:33:26 +0900 (Sun, 19 Apr 2009) New Revision: 23218 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23218 Log: merges r22990 from trunk into ruby_1_9_1. -- make ./goruby -e 'p "abc".gs(/a/) { $& }' prints "abc". Modified files: branches/ruby_1_9_1/golf_prelude.rb Index: ruby_1_9_1/golf_prelude.rb =================================================================== --- ruby_1_9_1/golf_prelude.rb (revision 23217) +++ ruby_1_9_1/golf_prelude.rb (revision 23218) @@ -2,13 +2,20 @@ @@golf_hash = {} def method_missing m, *a, &b t = @@golf_hash[ [m,self.class] ] ||= matching_methods(m)[0] - t ? __send__(t, *a, &b) : super + if t && b + __send__(t, *a) {|*args| + b.binding.eval("proc{|golf_matchdata| $~ = golf_matchdata }").call($~) if $~ + b.call(*args) + } + else + t ? __send__(t, *a, &b) : super + end end def matching_methods(s='', m=callable_methods) r=/^#{s.to_s.gsub(/./){"(.*?)"+Regexp.escape($&)}}/ m.grep(r).sort_by do |i| - i.to_s.match(r).captures.map(&:size)<<i + i.to_s.match(r).captures.map(&:size) << i end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/