I've looked through these docs and Google, and can't seem to find the purpose of .rewind
, and how it differs from .close
, in the context of working with a Tempfile
.
Also, why does .read
return an empty string before rewinding?
Here is an example:
file = Tempfile.new('foo')
file.path # => A unique filename in the OS's temp directory,
# e.g.: "/tmp/foo.24722.0"
# This filename contains 'foo' in its basename.
file.write("hello world")
file.rewind
file.read # => "hello world"
file.close
file.unlink # deletes the temp file