Prefer block forms to close opened files
This commit is contained in:
parent
d05a268adc
commit
b4eba8dfee
@ -510,22 +510,24 @@ if defined? Zlib
|
||||
gz = Zlib::GzipWriter.new(t)
|
||||
gz.print("foo")
|
||||
gz.close
|
||||
t = File.open(t.path, 'ab')
|
||||
gz = Zlib::GzipWriter.new(t)
|
||||
File.open(t.path, 'ab') do |f|
|
||||
gz = Zlib::GzipWriter.new(f)
|
||||
gz.print("bar")
|
||||
gz.close
|
||||
end
|
||||
|
||||
results = []
|
||||
t = File.open(t.path, 'rb')
|
||||
Zlib::GzipReader.zcat(t) do |str|
|
||||
File.open(t.path, 'rb') do |f|
|
||||
Zlib::GzipReader.zcat(f) do |str|
|
||||
results << str
|
||||
end
|
||||
end
|
||||
assert_equal(["foo", "bar"], results)
|
||||
t.close
|
||||
|
||||
t = File.open(t.path, 'rb')
|
||||
assert_equal("foobar", Zlib::GzipReader.zcat(t))
|
||||
t.close
|
||||
results = File.open(t.path, 'rb') do |f|
|
||||
Zlib::GzipReader.zcat(f)
|
||||
end
|
||||
assert_equal("foobar", results)
|
||||
}
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user