Mega Code Archive

 
Categories / Ruby / File Directory
 

Use Dir tmpdir with File join to create a platform-independent way of creating a temporary file

require 'tmpdir' tempfilename = File.join(Dir.tmpdir, "myapp.dat") tempfile = File.new(tempfilename, "w") tempfile.puts "This is only temporary" tempfile.close File.delete(tempfilename)