Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
Forked from nuna/tempfile-right.rb
Created April 27, 2011 07:50
Show Gist options
  • Save ongaeshi/943877 to your computer and use it in GitHub Desktop.
Save ongaeshi/943877 to your computer and use it in GitHub Desktop.
tempfileへの書き込み関数
require 'tempfile'
str = <<EOF
Lorem ipsum
Lorem ipsum dolor sit amet,
consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
EOF
def tempwrite(basename, str)
f = Tempfile.new(basename)
f.print str
f.close
return f
end
temp = tempwrite("temp", str)
GC.start
File.open(temp.path) do |f|
print f.read
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment