mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 10:33:58 +02:00
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:
parent
fec18c0bc2
commit
30b0fe4cc2
4 changed files with 35 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue