summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-25 14:22:37 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-01 02:28:49 +0900
commitd752cf7601adbe4bc2dc658effc2f61563a7dfb7 (patch)
tree7acc875d1933b330f96c7e3d7a31d61da5e77387 /tool
parenta0b0365e905e1ac51998ace7e6fc723406a2f157 (diff)
Use class methods of `File` over `Kernel.open` and `IO.read`
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6834
Diffstat (limited to 'tool')
-rw-r--r--tool/lib/test/unit.rb2
-rw-r--r--tool/lib/webrick/httputils.rb2
-rw-r--r--tool/mk_builtin_loader.rb6
-rw-r--r--tool/test/webrick/test_filehandler.rb4
-rw-r--r--tool/test/webrick/test_httprequest.rb2
-rw-r--r--tool/transcode-tblgen.rb2
6 files changed, 9 insertions, 9 deletions
diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb
index 0449fa215a..0fa7b4c5cd 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -729,7 +729,7 @@ module Test
return result
ensure
if file = @options[:timetable_data]
- open(file, 'w'){|f|
+ File.open(file, 'w'){|f|
@records.each{|(worker, suite), (st, ed)|
f.puts '[' + [worker.dump, suite.dump, st.to_f * 1_000, ed.to_f * 1_000].join(", ") + '],'
}
diff --git a/tool/lib/webrick/httputils.rb b/tool/lib/webrick/httputils.rb
index f1b9ddf9f0..e21284ee7f 100644
--- a/tool/lib/webrick/httputils.rb
+++ b/tool/lib/webrick/httputils.rb
@@ -112,7 +112,7 @@ module WEBrick
def load_mime_types(file)
# note: +file+ may be a "| command" for now; some people may
# rely on this, but currently we do not use this method by default.
- open(file){ |io|
+ File.open(file){ |io|
hash = Hash.new
io.each{ |line|
next if /^#/ =~ line
diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb
index c4f36889d6..94af846a7e 100644
--- a/tool/mk_builtin_loader.rb
+++ b/tool/mk_builtin_loader.rb
@@ -276,10 +276,10 @@ def mk_builtin_header file
collect_builtin(base, Ripper.sexp(code), 'top', bs = {}, inlines = {})
begin
- f = open(ofile, 'w')
- rescue Errno::EACCES
+ f = File.open(ofile, 'w')
+ rescue SystemCallError # EACCES, EPERM, EROFS, etc.
# Fall back to the current directory
- f = open(File.basename(ofile), 'w')
+ f = File.open(File.basename(ofile), 'w')
end
begin
if File::ALT_SEPARATOR
diff --git a/tool/test/webrick/test_filehandler.rb b/tool/test/webrick/test_filehandler.rb
index 146d8ce792..9c5b83e300 100644
--- a/tool/test/webrick/test_filehandler.rb
+++ b/tool/test/webrick/test_filehandler.rb
@@ -85,12 +85,12 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
"Content-Type: text/plain\r\n" \
"Content-Range: bytes 0-0/#{filesize}\r\n" \
"\r\n" \
- "#{IO.read(__FILE__, 1)}\r\n" \
+ "#{File.read(__FILE__, 1)}\r\n" \
"--#{boundary}\r\n" \
"Content-Type: text/plain\r\n" \
"Content-Range: bytes #{off}-#{last}/#{filesize}\r\n" \
"\r\n" \
- "#{IO.read(__FILE__, 2, off)}\r\n" \
+ "#{File.read(__FILE__, 2, off)}\r\n" \
"--#{boundary}--\r\n"
assert_equal exp, body
end
diff --git a/tool/test/webrick/test_httprequest.rb b/tool/test/webrick/test_httprequest.rb
index 759ccbdada..3c0ea937d9 100644
--- a/tool/test/webrick/test_httprequest.rb
+++ b/tool/test/webrick/test_httprequest.rb
@@ -245,7 +245,7 @@ GET /
_end_of_message_
msg.gsub!(/^ {6}/, "")
- open(__FILE__){|io|
+ File.open(__FILE__){|io|
while chunk = io.read(100)
msg << chunk.size.to_s(16) << crlf
msg << chunk << crlf
diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb
index dba6f33ff9..b19f68bac4 100644
--- a/tool/transcode-tblgen.rb
+++ b/tool/transcode-tblgen.rb
@@ -725,7 +725,7 @@ def citrus_decode_mapsrc(ces, csid, mapsrcs)
path << ".src"
path[path.rindex('/')] = '%'
STDOUT.puts 'load mapsrc %s' % path if VERBOSE_MODE > 1
- open(path, 'rb') do |f|
+ File.open(path, 'rb') do |f|
f.each_line do |l|
break if /^BEGIN_MAP/ =~ l
end