ruby-changes:12233
From: shyouhei <ko1@a...>
Date: Wed, 1 Jul 2009 15:48:39 +0900 (JST)
Subject: [ruby-changes:12233] Ruby:r23920 (ruby_1_8_7): merge revision(s) 22988:
shyouhei 2009-07-01 15:48:23 +0900 (Wed, 01 Jul 2009) New Revision: 23920 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23920 Log: merge revision(s) 22988: * lib/pathname.rb (Pathname#sub): set $~ in block.binding. [ruby-dev:38173] Modified files: branches/ruby_1_8_7/ChangeLog branches/ruby_1_8_7/lib/pathname.rb branches/ruby_1_8_7/test/pathname/test_pathname.rb branches/ruby_1_8_7/version.h Index: ruby_1_8_7/ChangeLog =================================================================== --- ruby_1_8_7/ChangeLog (revision 23919) +++ ruby_1_8_7/ChangeLog (revision 23920) @@ -1,3 +1,8 @@ +Wed Jul 1 15:46:30 2009 Tanaka Akira <akr@f...> + + * lib/pathname.rb (Pathname#sub): set $~ in block.binding. + [ruby-dev:38173] + Mon Jun 29 13:18:42 2009 Yukihiro Matsumoto <matz@r...> * lib/fileutils.rb (FileUtils#fu_get_gid): stringify group Index: ruby_1_8_7/version.h =================================================================== --- ruby_1_8_7/version.h (revision 23919) +++ ruby_1_8_7/version.h (revision 23920) @@ -1,15 +1,15 @@ #define RUBY_VERSION "1.8.7" -#define RUBY_RELEASE_DATE "2009-06-29" +#define RUBY_RELEASE_DATE "2009-07-01" #define RUBY_VERSION_CODE 187 -#define RUBY_RELEASE_CODE 20090629 -#define RUBY_PATCHLEVEL 175 +#define RUBY_RELEASE_CODE 20090701 +#define RUBY_PATCHLEVEL 176 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_TEENY 7 #define RUBY_RELEASE_YEAR 2009 -#define RUBY_RELEASE_MONTH 6 -#define RUBY_RELEASE_DAY 29 +#define RUBY_RELEASE_MONTH 7 +#define RUBY_RELEASE_DAY 1 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; @@ -29,3 +29,4 @@ #define RUBY_RELEASE_NUM RUBY_PATCHLEVEL + Index: ruby_1_8_7/lib/pathname.rb =================================================================== --- ruby_1_8_7/lib/pathname.rb (revision 23919) +++ ruby_1_8_7/lib/pathname.rb (revision 23920) @@ -251,7 +251,21 @@ # Return a pathname which is substituted by String#sub. def sub(pattern, *rest, &block) - self.class.new(@path.sub(pattern, *rest, &block)) + if block + path = @path.sub(pattern, *rest) {|*args| + begin + old = Thread.current[:pathname_sub_matchdata] + Thread.current[:pathname_sub_matchdata] = $~ + eval("$~ = Thread.current[:pathname_sub_matchdata]", block.binding) + ensure + Thread.current[:pathname_sub_matchdata] = old + end + yield *args + } + else + path = @path.sub(pattern, *rest) + end + self.class.new(path) end if File::ALT_SEPARATOR Index: ruby_1_8_7/test/pathname/test_pathname.rb =================================================================== --- ruby_1_8_7/test/pathname/test_pathname.rb (revision 23919) +++ ruby_1_8_7/test/pathname/test_pathname.rb (revision 23920) @@ -381,6 +381,15 @@ def pathsub(path, pat, repl) Pathname.new(path).sub(pat, repl).to_s end defassert(:pathsub, "a.o", "a.c", /\.c\z/, ".o") + def test_sub_matchdata + result = Pathname("abc.gif").sub(/\..*/) { + assert_not_nil($~) + assert_equal(".gif", $~[0]) + ".png" + } + assert_equal("abc.png", result.to_s) + end + def root?(path) Pathname.new(path).root? end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/