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
This commit is contained in:
shyouhei 2009-07-01 06:48:23 +00:00
parent fec18c0bc2
commit 30b0fe4cc2
4 changed files with 35 additions and 6 deletions

View file

@ -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> Mon Jun 29 13:18:42 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/fileutils.rb (FileUtils#fu_get_gid): stringify group * lib/fileutils.rb (FileUtils#fu_get_gid): stringify group

View file

@ -251,7 +251,21 @@ class Pathname
# Return a pathname which is substituted by String#sub. # Return a pathname which is substituted by String#sub.
def sub(pattern, *rest, &block) 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 end
if File::ALT_SEPARATOR if File::ALT_SEPARATOR

View file

@ -381,6 +381,15 @@ class TestPathname < Test::Unit::TestCase
def pathsub(path, pat, repl) Pathname.new(path).sub(pat, repl).to_s end def pathsub(path, pat, repl) Pathname.new(path).sub(pat, repl).to_s end
defassert(:pathsub, "a.o", "a.c", /\.c\z/, ".o") 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) def root?(path)
Pathname.new(path).root? Pathname.new(path).root?
end end

View file

@ -1,15 +1,15 @@
#define RUBY_VERSION "1.8.7" #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_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20090629 #define RUBY_RELEASE_CODE 20090701
#define RUBY_PATCHLEVEL 175 #define RUBY_PATCHLEVEL 176
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8 #define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 7 #define RUBY_VERSION_TEENY 7
#define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_YEAR 2009
#define RUBY_RELEASE_MONTH 6 #define RUBY_RELEASE_MONTH 7
#define RUBY_RELEASE_DAY 29 #define RUBY_RELEASE_DAY 1
#ifdef RUBY_EXTERN #ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];
@ -29,3 +29,4 @@ RUBY_EXTERN const char *ruby_copyright;
#define RUBY_RELEASE_NUM RUBY_PATCHLEVEL #define RUBY_RELEASE_NUM RUBY_PATCHLEVEL