Sha256: e69f01a8c6faaf48dea55573186d7f4ad5a516b5117dc3dcb25968fb5b6a27d3

Contents?: true

Size: 447 Bytes

Versions: 1

Compression:

Stored size: 447 Bytes

Contents

require 'tempfile'

module Tins
  module TempIO
    def temp_io(content = nil)
      Tempfile.open(__method__.to_s, binmode: true) do |io|
        if content.respond_to?(:call)
          if content.respond_to?(:arity) && content.arity == 1
            content.call(io)
          else
            io.write content.call
          end
        else
          io.write content
        end
        io.rewind
        yield io
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tins-1.16.1 lib/tins/temp_io.rb