在雾存储中上传文件时,不需要关闭ruby文件对象?

在雾存储中上传文件时,不需要关闭ruby文件对象?

问题描述:

焕我看着雾文档在http://fog.io/storage/,例子说:在雾存储中上传文件时,不需要关闭ruby文件对象?

# upload that resume 
file = directory.files.create(
    :key => 'resume.html', 
    :body => File.open("/path/to/my/resume.html"), 
    :public => true 
) 

File.open(...)返回文件对象,但我不知道何时关闭?在下面的详细地质矿产保守或不要紧?:

# upload that resume 
File.open("/path/to/my/resume.html") do |f| 
    file = directory.files.create(
    :key => 'resume.html', 
    :body => f, 
    :public => true 
) 
end 

我不认为在这种情况下,将可以显式关闭(这样或许文档应更新)。剩下的只是文件句柄,它不应该太有影响(与文件的内容相比,这些内容只能在一次发布时使用)。因此,您列出的第二个保守选项可能更为正确,但在大多数情况下,这两种方式可能无关紧要。

+0

谢谢!我了解这一点。 –