小编Jon*_*orn的帖子

.rewind方法对ruby中的Tempfile有什么作用?

我已经通过看这些文档和谷歌,似乎无法找到的目的.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
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails stringio

12
推荐指数
1
解决办法
3032
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1

stringio ×1