From be9a32b65ff5e72f54365e79338516d46063e069 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 May 2018 19:26:56 +0200 Subject: 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. --- railties/test/generators/actions_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test/generators/actions_test.rb') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index f421207025..a54a6dbc28 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -403,7 +403,7 @@ class ActionsTest < Rails::Generators::TestCase content.gsub!(/^ \#.*\n/, "") content.gsub!(/^\n/, "") - File.open(route_path, "wb") { |file| file.write(content) } + File.write(route_path, content) routes = <<-F Rails.application.routes.draw do -- cgit v1.2.3