Reason #164 • June 13th, 2026

Writing a file

Ruby
File.write "greeting.txt", "Hello, world!"
# => 13
    

Know what I'm saying?

History

File.write shipped with Ruby 1.9.3, released on October 30, 2011, together with File.binwrite for writing binary content.

Before this, we would have used the more verbose block style: File.open("greeting.txt", "w") { |f| f.write("Hello, world!") }.

Reason #165 ?