Module: TempfileHelper
Instance Method Summary collapse
Instance Method Details
#read(name = nil) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/tempfile_helper.rb', line 6 def read(name = nil) tempfile = nil name ||= Time.now.to_f Tempfile.open(name) { |tempfile| yield(tempfile) } File.read(tempfile.path) end |
#write(content, name = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/tempfile_helper.rb', line 13 def write(content, name = nil) name ||= Time.now.to_f.to_s file = Tempfile.new(name) file.write(content) file.close file end |