# File lib/diffy/diff.rb, line 43
    def diff
      @diff ||= begin
        @paths = case options[:source]
          when 'strings'
            [tempfile(string1), tempfile(string2)]
          when 'files'
            [string1, string2]
          end

        if WINDOWS
          # don't use open3 on windows
          cmd = sprintf '"%s" %s %s', diff_bin, diff_options.join(' '), @paths.map { |s| %("#{s}") }.join(' ')
          diff = `#{cmd}`
        else
          diff = Open3.popen3(diff_bin, *(diff_options + @paths)) { |i, o, e| o.read }
        end
        diff.force_encoding('ASCII-8BIT') if diff.respond_to?(:valid_encoding?) && !diff.valid_encoding?
        if diff =~ /\A\s*\Z/ && !options[:allow_empty_diff]
          diff = case options[:source]
          when 'strings' then string1
          when 'files' then File.read(string1)
          end.gsub(/^/, " ")
        end
        diff
      end
    ensure
      # unlink the tempfiles explicitly now that the diff is generated
      if defined? @tempfiles # to avoid Ruby warnings about undefined ins var.
        Array(@tempfiles).each do |t|
          begin
            # check that the path is not nil and file still exists.
            # REE seems to be very agressive with when it magically removes
            # tempfiles
            t.unlink if t.path && File.exist?(t.path)
          rescue => e
            warn "#{e.class}: #{e}"
            warn e.backtrace.join("\n")
          end
        end
      end
    end