Method: FakeFS::Pathname#sub
- Defined in:
- lib/fakefs/pathname.rb
#sub(pattern, *rest, &block) ⇒ Object
Return a pathname which is substituted by String#sub.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fakefs/pathname.rb', line 99 def sub(pattern, *rest, &block) if block path = @path.sub(pattern, *rest) do |*args| begin old = Thread.current[:pathname_sub_matchdata] Thread.current[:pathname_sub_matchdata] = $LAST_MATCH_INFO eval('$~ = Thread.current[:pathname_sub_matchdata]', block.binding) ensure Thread.current[:pathname_sub_matchdata] = old end yield(*args) end else path = @path.sub(pattern, *rest) end self.class.new(path) end |