Prefer to use File.foreach instead of IO.foreach

This commit is contained in:
Hiroshi SHIBATA 2023-02-27 16:38:32 +09:00
Родитель d063ed12af
Коммит db0a4c8923
11 изменённых файлов: 14 добавлений и 14 удалений

Просмотреть файл

@ -23,7 +23,7 @@ until ARGV.empty?
end end
end end
IO.foreach("#{srcdir}/configure.ac") do |line| File.foreach("#{srcdir}/configure.ac") do |line|
if /^AC_INIT\((.*)\)/ =~ line if /^AC_INIT\((.*)\)/ =~ line
version = $1.split(/,\s*/)[1] version = $1.split(/,\s*/)[1]
version.gsub!(/\A\[|\]\z/, '') version.gsub!(/\A\[|\]\z/, '')

Просмотреть файл

@ -4,7 +4,7 @@ require_relative '../http'
if $0 == __FILE__ if $0 == __FILE__
require 'open-uri' require 'open-uri'
IO.foreach(__FILE__) do |line| File.foreach(__FILE__) do |line|
puts line puts line
break if line.start_with?('end') break if line.start_with?('end')
end end

Просмотреть файл

@ -37,7 +37,7 @@ TestComprehensiveCaseMapping.data_files_available? and class TestComprehensiveC
end end
def self.read_data_file(filename) 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 $. == 1
if filename == 'UnicodeData' if filename == 'UnicodeData'
elsif line.start_with?("# #{filename}-#{UNICODE_VERSION}.txt") elsif line.start_with?("# #{filename}-#{UNICODE_VERSION}.txt")

Просмотреть файл

@ -75,7 +75,7 @@ class TestEmojiBreaks < Test::Unit::TestCase
EMOJI_DATA_FILES.each do |file| EMOJI_DATA_FILES.each do |file|
version_mismatch = true version_mismatch = true
file_tests = [] file_tests = []
IO.foreach(file.fullname, encoding: Encoding::UTF_8) do |line| File.foreach(file.fullname, encoding: Encoding::UTF_8) do |line|
line.chomp! line.chomp!
if $.==1 if $.==1
if line=="# #{file.basename}-#{file.version}.txt" if line=="# #{file.basename}-#{file.version}.txt"

Просмотреть файл

@ -44,7 +44,7 @@ class TestGraphemeBreaksFromFile < Test::Unit::TestCase
if file_available? if file_available?
def read_data def read_data
tests = [] 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") if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
raise "File Version Mismatch" raise "File Version Mismatch"
end end

Просмотреть файл

@ -61,7 +61,7 @@ class CaseFolding
@version = nil @version = nil
turkic = [] turkic = []
IO.foreach(filename, mode: "rb") do |line| File.foreach(filename, mode: "rb") do |line|
@version ||= line[/-([0-9.]+).txt/, 1] @version ||= line[/-([0-9.]+).txt/, 1]
next unless res = pattern.match(line) next unless res = pattern.match(line)
ch_from = res[1].to_i(16) ch_from = res[1].to_i(16)
@ -230,7 +230,7 @@ class CaseMapping
@specials = [] @specials = []
@specials_length = 0 @specials_length = 0
@version = nil @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 =~ /^</ next if line =~ /^</
code, _, _, _, _, _, _, _, _, _, _, _, upper, lower, title = line.chomp.split ';' code, _, _, _, _, _, _, _, _, _, _, _, upper, lower, title = line.chomp.split ';'
unless upper and lower and title and (upper+lower+title)=='' unless upper and lower and title and (upper+lower+title)==''
@ -239,7 +239,7 @@ class CaseMapping
end end
@filename = File.join(mapping_directory, 'SpecialCasing.txt') @filename = File.join(mapping_directory, 'SpecialCasing.txt')
IO.foreach(@filename, mode: "rb") do |line| File.foreach(@filename, mode: "rb") do |line|
@version ||= line[/-([0-9.]+).txt/, 1] @version ||= line[/-([0-9.]+).txt/, 1]
line.chomp! line.chomp!
line, comment = line.split(/ *#/) line, comment = line.split(/ *#/)

Просмотреть файл

@ -59,7 +59,7 @@ def parse_unicode_data(file)
data = {'Any' => (0x0000..0x10ffff).to_a, 'Assigned' => [], data = {'Any' => (0x0000..0x10ffff).to_a, 'Assigned' => [],
'ASCII' => (0..0x007F).to_a, 'NEWLINE' => [0x0a], 'Cn' => []} 'ASCII' => (0..0x007F).to_a, 'NEWLINE' => [0x0a], 'Cn' => []}
beg_cp = nil beg_cp = nil
IO.foreach(file) do |line| File.foreach(file) do |line|
fields = line.split(';') fields = line.split(';')
cp = fields[0].to_i(16) cp = fields[0].to_i(16)

Просмотреть файл

@ -185,7 +185,7 @@ class ExtLibs
extracted = false extracted = false
dest = File.dirname(list) dest = File.dirname(list)
url = chksums = nil url = chksums = nil
IO.foreach(list) do |line| File.foreach(list) do |line|
line.sub!(/\s*#.*/, '') line.sub!(/\s*#.*/, '')
if /^(\w+)\s*=\s*(.*)/ =~ line if /^(\w+)\s*=\s*(.*)/ =~ line
vars[$1] = vars.expand($2) vars[$1] = vars.expand($2)

Просмотреть файл

@ -12,7 +12,7 @@ module Memory
PROC_FILE = procfile PROC_FILE = procfile
VM_PAT = pat VM_PAT = pat
def self.read_status 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 yield($1.downcase.intern, $2.to_i * 1024) if VM_PAT =~ l
end end
end end

Просмотреть файл

@ -205,7 +205,7 @@ print " CONFIG = {}\n"
print " CONFIG[\"DESTDIR\"] = DESTDIR\n" print " CONFIG[\"DESTDIR\"] = DESTDIR\n"
versions = {} 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) m = /^\s*#\s*define\s+RUBY_(PATCHLEVEL)\s+(-?\d+)/.match(l)
if m if m
versions[m[1]] = m[2] versions[m[1]] = m[2]
@ -226,7 +226,7 @@ IO.foreach(File.join(srcdir, "version.h")) do |l|
end end
end end
if versions.size != 4 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) m = /^\s*#\s*define\s+RUBY_API_VERSION_(\w+)\s+(-?\d+)/.match(l)
if m if m
versions[m[1]] ||= m[2] versions[m[1]] ||= m[2]

Просмотреть файл

@ -49,7 +49,7 @@ class Exports
end end
def read_substitution(header, syms, winapis) 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 if /^#define (\w+)\((.*?)\)\s+(?:\(void\))?(rb_w32_\w+)\((.*?)\)\s*$/ =~ line and
$2.delete(" ") == $4.delete(" ") $2.delete(" ") == $4.delete(" ")
export, internal = $1, $3 export, internal = $1, $3