I looked through these documents and Google and it seems that I can not find the target .rewind , and how it differs from .close , in the context of working with Tempfile .
Also, why .read returns an empty string before rewinding?
Here is an example:
file = Tempfile.new('foo') file.path # => A unique filename in the OS temp directory, # eg: "/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
source share