ruby-changes:65128
From: Nobuyoshi <ko1@a...>
Date: Wed, 3 Feb 2021 17:38:20 +0900 (JST)
Subject: [ruby-changes:65128] b4eba8dfee (master): Prefer block forms to close opened files
https://git.ruby-lang.org/ruby.git/commit/?id=b4eba8dfee From b4eba8dfee50a8b9085b32a1750be5313b9cf96b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 3 Feb 2021 17:34:41 +0900 Subject: Prefer block forms to close opened files --- test/zlib/test_zlib.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index 42ee5c6..e6d61ca 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -510,22 +510,24 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L510 gz = Zlib::GzipWriter.new(t) gz.print("foo") gz.close - t = File.open(t.path, 'ab') - gz = Zlib::GzipWriter.new(t) - gz.print("bar") - gz.close + 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| - results << 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/