[前][次][番号順一覧][スレッド一覧]

ruby-changes:11370

From: akr <ko1@a...>
Date: Tue, 17 Mar 2009 15:40:25 +0900 (JST)
Subject: [ruby-changes:11370] Ruby:r22990 (trunk): make ./goruby -e 'p "abc".gs(/a/) { $& }' prints "abc".

akr	2009-03-17 15:40:20 +0900 (Tue, 17 Mar 2009)

  New Revision: 22990

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22990

  Log:
    make ./goruby -e 'p "abc".gs(/a/) { $& }' prints "abc".

  Modified files:
    trunk/golf_prelude.rb

Index: golf_prelude.rb
===================================================================
--- golf_prelude.rb	(revision 22989)
+++ golf_prelude.rb	(revision 22990)
@@ -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/

[前][次][番号順一覧][スレッド一覧]