[前][次][番号順一覧][スレッド一覧]

ruby-changes:73358

From: Nobuyoshi <ko1@a...>
Date: Thu, 1 Sep 2022 19:39:43 +0900 (JST)
Subject: [ruby-changes:73358] 762fca9b12 (master): Prefer `File` class methods to write a string

https://git.ruby-lang.org/ruby.git/commit/?id=762fca9b12

From 762fca9b12b9cfb0159404c95ee4275100169c17 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 31 Aug 2022 21:53:01 +0900
Subject: Prefer `File` class methods to write a string

---
 tool/make-snapshot | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/tool/make-snapshot b/tool/make-snapshot
index f91ab8855f..6b02da5139 100755
--- a/tool/make-snapshot
+++ b/tool/make-snapshot
@@ -345,7 +345,7 @@ def package(vcs, rev, destdir, tmp = nil) https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L345
     v = v[0]
   end
 
-  open("#{v}/revision.h", "wb") {|f|
+  File.open("#{v}/revision.h", "wb") {|f|
     short = vcs.short_revision(revision)
     f.puts "#define RUBY_REVISION #{short.inspect}"
     unless short == revision
@@ -391,6 +391,7 @@ def package(vcs, rev, destdir, tmp = nil) https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L391
     return
   end
   def (clean = []).add(n) push(n); n end
+  def clean.create(file, content = "") File.binwrite(add(file), content) end
   Dir.chdir(v) do
     unless File.exist?("ChangeLog")
       vcs.export_changelog(url, nil, revision, "ChangeLog")
@@ -438,14 +439,12 @@ def package(vcs, rev, destdir, tmp = nil) https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L439
       rescue Errno::ENOENT
         # use fallback file
       end
-      File.open(clean.add("config.status"), "w") {|f|
-        f.print status
-      }
+      clean.create("config.status", status)
       FileUtils.mkpath(hdrdir = "#{extout}/include/ruby")
-      File.open("#{hdrdir}/config.h", "w") {}
+      File.binwrite("#{hdrdir}/config.h", "")
       FileUtils.mkpath(defaults = "#{extout}/rubygems/defaults")
-      File.open("#{defaults}/operating_system.rb", "w") {}
-      File.open("#{defaults}/ruby.rb", "w") {}
+      File.binwrite("#{defaults}/operating_system.rb", "")
+      File.binwrite("#{defaults}/ruby.rb", "")
       miniruby = ENV['MINIRUBY'] + " -I. -I#{extout} -rcross"
       baseruby = ENV["BASERUBY"]
       mk = (IO.read("template/Makefile.in") rescue IO.read("Makefile.in")).
@@ -481,11 +480,9 @@ update-gems: https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L480
 $(UNICODE_SRC_DATA_DIR)/.unicode-tables.time:
 touch-unicode-files:
       APPEND
-      open(clean.add("Makefile"), "w") do |f|
-        f.puts mk
-      end
-      File.open(clean.add("revision.tmp"), "w") {}
-      File.open(clean.add(".revision.time"), "w") {}
+      clean.create("Makefile", mk)
+      clean.create("revision.tmp")
+      clean.create(".revision.time")
       ENV["CACHE_SAVE"] = "no"
       make = MAKE.new(args)
       return unless make.run("update-download")
@@ -619,7 +616,7 @@ revisions.collect {|rev| package(vcs, rev, destdir, tmp)}.flatten.each do |name| https://github.com/ruby/ruby/blob/trunk/tool/make-snapshot#L616
     success = false
     next
   end
-  str = open(name, "rb") {|f| f.read}
+  str = File.binread(name)
   pathname = Pathname(name)
   basename = pathname.basename.to_s
   extname = pathname.extname.sub(/\A\./, '')
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]