Method: FakeFS::Pathname#sub
- Defined in:
- lib/fakefs/pathname.rb
#sub(pattern, *rest, &block) ⇒ Object
Return a pathname which is substituted by String#sub.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fakefs/pathname.rb', line 86 def sub(pattern, *rest, &block) path = if block @path.sub(pattern, *rest) do |*args| begin old = Thread.current[:pathname_sub_matchdata] Thread.current[:pathname_sub_matchdata] = $~ # TODO: rewrite without using eval eval( '$~ = Thread.current[:pathname_sub_matchdata]', block.binding, __FILE__, __LINE__ - 3 ) ensure Thread.current[:pathname_sub_matchdata] = old end yield(*args) end else @path.sub(pattern, *rest) end self.class.new(path) end |