aboutsummaryrefslogtreecommitdiffstats
path: root/tasks/release.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2018-05-05 19:26:56 +0200
committerXavier Noria <fxn@hashref.com>2018-05-05 19:38:38 +0200
commitbe9a32b65ff5e72f54365e79338516d46063e069 (patch)
tree19f779b946bdfd675edc4153ee43e2e020a751bb /tasks/release.rb
parent42b9e7e50c084e119a679cf155b70b5efc4d36ff (diff)
downloadrails-be9a32b65ff5e72f54365e79338516d46063e069.tar.gz
rails-be9a32b65ff5e72f54365e79338516d46063e069.tar.bz2
rails-be9a32b65ff5e72f54365e79338516d46063e069.zip
prefer File.write for bulk writes
I saw these ones while working on #32362. File.write was introduced in Ruby 1.9.3 and it is the most concise way to perform bulk writes (as File.read is for bulk reading). The existing flags enabled binmode, but we are dumping text here. The portable way to dump text is text mode. The only difference is newlines, and portable code should in particular emit portable newlines. Please note the hard-coded \ns are still correct. In languages with C semantics for newlines like Ruby, Python, Perl, and others, "\n" is a portable newline. Both when writing and when reading. On Windows, the I/O layer is responsible for prepending a CR before each LF on writing, and removing CRs followed by LFs on reading. On Unix, binmode is a no-op.
Diffstat (limited to 'tasks/release.rb')
-rw-r--r--tasks/release.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/tasks/release.rb b/tasks/release.rb
index e326021dad..cbda9a3798 100644
--- a/tasks/release.rb
+++ b/tasks/release.rb
@@ -107,7 +107,7 @@ namespace :changelog do
header = "## Rails #{version} (#{Date.today.strftime('%B %d, %Y')}) ##\n\n"
header += "* No changes.\n\n\n" if current_contents =~ /\A##/
contents = header + current_contents
- File.open(fname, "wb") { |f| f.write contents }
+ File.write(fname, contents)
end
end
@@ -118,7 +118,7 @@ namespace :changelog do
fname = File.join fw, "CHANGELOG.md"
contents = File.read(fname).sub(/^(## Rails .*)\n/, replace)
- File.open(fname, "wb") { |f| f.write contents }
+ File.write(fname, contents)
end
end