【发布时间】:2018-07-09 20:24:52
【问题描述】:
我浏览了 these docs 和 Google,似乎无法找到 .rewind 的用途,以及它与 .close 的区别,在使用 Tempfile 的情况下。
另外,为什么.read在倒带之前返回一个空字符串?
这是一个例子:
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
【问题讨论】:
标签: ruby-on-rails ruby stringio