summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-17 05:26:15 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-17 05:26:15 +0000
commita28532dcf3e237b8d75c724cd65eb04ca57e6da1 (patch)
tree8e8690ef4920c1981fc7749a2f146a9c4f4b4bc4 /lib
parent27a39b8ffed0c8317f5d44e21dee52e66ee66e40 (diff)
* lib/pathname.rb (Pathname#sub): set $~ in block.binding.
[ruby-dev:38173] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/pathname.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb
index 8a07d455fd..75faaef8b2 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -254,7 +254,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