From db0a4c8923e0e084c7d757d132a83fc9c8431633 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 27 Feb 2023 16:38:32 +0900 Subject: [PATCH] Prefer to use File.foreach instead of IO.foreach --- ext/fiddle/win32/libffi-config.rb | 2 +- lib/net/http/status.rb | 2 +- test/ruby/enc/test_case_comprehensive.rb | 2 +- test/ruby/enc/test_emoji_breaks.rb | 2 +- test/ruby/enc/test_grapheme_breaks.rb | 2 +- tool/enc-case-folding.rb | 6 +++--- tool/enc-unicode.rb | 2 +- tool/extlibs.rb | 2 +- tool/lib/memory_status.rb | 2 +- tool/mkconfig.rb | 4 ++-- win32/mkexports.rb | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ext/fiddle/win32/libffi-config.rb b/ext/fiddle/win32/libffi-config.rb index 1a750334ef..8e8069a943 100755 --- a/ext/fiddle/win32/libffi-config.rb +++ b/ext/fiddle/win32/libffi-config.rb @@ -23,7 +23,7 @@ until ARGV.empty? end end -IO.foreach("#{srcdir}/configure.ac") do |line| +File.foreach("#{srcdir}/configure.ac") do |line| if /^AC_INIT\((.*)\)/ =~ line version = $1.split(/,\s*/)[1] version.gsub!(/\A\[|\]\z/, '') diff --git a/lib/net/http/status.rb b/lib/net/http/status.rb index f39fb64256..9673005871 100644 --- a/lib/net/http/status.rb +++ b/lib/net/http/status.rb @@ -4,7 +4,7 @@ require_relative '../http' if $0 == __FILE__ require 'open-uri' - IO.foreach(__FILE__) do |line| + File.foreach(__FILE__) do |line| puts line break if line.start_with?('end') end diff --git a/test/ruby/enc/test_case_comprehensive.rb b/test/ruby/enc/test_case_comprehensive.rb index bc57d57ee4..de18ac865c 100644 --- a/test/ruby/enc/test_case_comprehensive.rb +++ b/test/ruby/enc/test_case_comprehensive.rb @@ -37,7 +37,7 @@ TestComprehensiveCaseMapping.data_files_available? and class TestComprehensiveC end def self.read_data_file(filename) - IO.foreach(expand_filename(filename), encoding: Encoding::ASCII_8BIT) do |line| + File.foreach(expand_filename(filename), encoding: Encoding::ASCII_8BIT) do |line| if $. == 1 if filename == 'UnicodeData' elsif line.start_with?("# #{filename}-#{UNICODE_VERSION}.txt") diff --git a/test/ruby/enc/test_emoji_breaks.rb b/test/ruby/enc/test_emoji_breaks.rb index 3e2999d61e..bb5114680e 100644 --- a/test/ruby/enc/test_emoji_breaks.rb +++ b/test/ruby/enc/test_emoji_breaks.rb @@ -75,7 +75,7 @@ class TestEmojiBreaks < Test::Unit::TestCase EMOJI_DATA_FILES.each do |file| version_mismatch = true file_tests = [] - IO.foreach(file.fullname, encoding: Encoding::UTF_8) do |line| + File.foreach(file.fullname, encoding: Encoding::UTF_8) do |line| line.chomp! if $.==1 if line=="# #{file.basename}-#{file.version}.txt" diff --git a/test/ruby/enc/test_grapheme_breaks.rb b/test/ruby/enc/test_grapheme_breaks.rb index f4e3c93b47..7e6d722d40 100644 --- a/test/ruby/enc/test_grapheme_breaks.rb +++ b/test/ruby/enc/test_grapheme_breaks.rb @@ -44,7 +44,7 @@ class TestGraphemeBreaksFromFile < Test::Unit::TestCase if file_available? def read_data tests = [] - IO.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line| + File.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line| if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt") raise "File Version Mismatch" end diff --git a/tool/enc-case-folding.rb b/tool/enc-case-folding.rb index 76c6b5c48b..82fec7b625 100755 --- a/tool/enc-case-folding.rb +++ b/tool/enc-case-folding.rb @@ -61,7 +61,7 @@ class CaseFolding @version = nil turkic = [] - IO.foreach(filename, mode: "rb") do |line| + File.foreach(filename, mode: "rb") do |line| @version ||= line[/-([0-9.]+).txt/, 1] next unless res = pattern.match(line) ch_from = res[1].to_i(16) @@ -230,7 +230,7 @@ class CaseMapping @specials = [] @specials_length = 0 @version = nil - IO.foreach(File.join(mapping_directory, 'UnicodeData.txt'), mode: "rb") do |line| + File.foreach(File.join(mapping_directory, 'UnicodeData.txt'), mode: "rb") do |line| next if line =~ /^ (0x0000..0x10ffff).to_a, 'Assigned' => [], 'ASCII' => (0..0x007F).to_a, 'NEWLINE' => [0x0a], 'Cn' => []} beg_cp = nil - IO.foreach(file) do |line| + File.foreach(file) do |line| fields = line.split(';') cp = fields[0].to_i(16) diff --git a/tool/extlibs.rb b/tool/extlibs.rb index b482258a2c..887cac61eb 100755 --- a/tool/extlibs.rb +++ b/tool/extlibs.rb @@ -185,7 +185,7 @@ class ExtLibs extracted = false dest = File.dirname(list) url = chksums = nil - IO.foreach(list) do |line| + File.foreach(list) do |line| line.sub!(/\s*#.*/, '') if /^(\w+)\s*=\s*(.*)/ =~ line vars[$1] = vars.expand($2) diff --git a/tool/lib/memory_status.rb b/tool/lib/memory_status.rb index 5e9e80a68a..60632523a8 100644 --- a/tool/lib/memory_status.rb +++ b/tool/lib/memory_status.rb @@ -12,7 +12,7 @@ module Memory PROC_FILE = procfile VM_PAT = pat def self.read_status - IO.foreach(PROC_FILE, encoding: Encoding::ASCII_8BIT) do |l| + File.foreach(PROC_FILE, encoding: Encoding::ASCII_8BIT) do |l| yield($1.downcase.intern, $2.to_i * 1024) if VM_PAT =~ l end end diff --git a/tool/mkconfig.rb b/tool/mkconfig.rb index 7a447fb234..131b2a311a 100755 --- a/tool/mkconfig.rb +++ b/tool/mkconfig.rb @@ -205,7 +205,7 @@ print " CONFIG = {}\n" print " CONFIG[\"DESTDIR\"] = DESTDIR\n" versions = {} -IO.foreach(File.join(srcdir, "version.h")) do |l| +File.foreach(File.join(srcdir, "version.h")) do |l| m = /^\s*#\s*define\s+RUBY_(PATCHLEVEL)\s+(-?\d+)/.match(l) if m versions[m[1]] = m[2] @@ -226,7 +226,7 @@ IO.foreach(File.join(srcdir, "version.h")) do |l| end end if versions.size != 4 - IO.foreach(File.join(srcdir, "include/ruby/version.h")) do |l| + File.foreach(File.join(srcdir, "include/ruby/version.h")) do |l| m = /^\s*#\s*define\s+RUBY_API_VERSION_(\w+)\s+(-?\d+)/.match(l) if m versions[m[1]] ||= m[2] diff --git a/win32/mkexports.rb b/win32/mkexports.rb index 40f055dee7..2889908942 100755 --- a/win32/mkexports.rb +++ b/win32/mkexports.rb @@ -49,7 +49,7 @@ class Exports end def read_substitution(header, syms, winapis) - IO.foreach(header) do |line| + File.foreach(header) do |line| if /^#define (\w+)\((.*?)\)\s+(?:\(void\))?(rb_w32_\w+)\((.*?)\)\s*$/ =~ line and $2.delete(" ") == $4.delete(" ") export, internal = $1, $3