summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-01 06:48:23 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-01 06:48:23 +0000
commit30b0fe4cc2dc3489c1105fe41050c0116186e61a (patch)
treec9934521ad123356dfe22745dd2d4eb85b625c7e /lib
parentfec18c0bc2656e1bc7afd4ec1f99523555e75616 (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
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 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