diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-01 06:48:23 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-01 06:48:23 +0000 |
commit | 30b0fe4cc2dc3489c1105fe41050c0116186e61a (patch) | |
tree | c9934521ad123356dfe22745dd2d4eb85b625c7e | |
parent | fec18c0bc2656e1bc7afd4ec1f99523555e75616 (diff) |
merge revision(s) 22988:
* lib/pathname.rb (Pathname#sub): set $~ in block.binding.
[ruby-dev:38173]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@23920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/pathname.rb | 16 | ||||
-rw-r--r-- | test/pathname/test_pathname.rb | 9 | ||||
-rw-r--r-- | version.h | 11 |
4 files changed, 35 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Wed Jul 1 15:46:30 2009 Tanaka Akira <akr@fsij.org> + + * lib/pathname.rb (Pathname#sub): set $~ in block.binding. + [ruby-dev:38173] + Mon Jun 29 13:18:42 2009 Yukihiro Matsumoto <matz@ruby-lang.org> * lib/fileutils.rb (FileUtils#fu_get_gid): stringify group diff --git a/lib/pathname.rb b/lib/pathname.rb index e4ca5489ce..86c4b98ee7 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -251,7 +251,21 @@ class Pathname # 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 diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 9b0b9c01e8..f94c123dec 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -381,6 +381,15 @@ class TestPathname < Test::Unit::TestCase 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 @@ -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 @@ RUBY_EXTERN const char *ruby_copyright; #define RUBY_RELEASE_NUM RUBY_PATCHLEVEL + |