# File lib/fakefs/pathname.rb, line 100
      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