Ruby 3 · Errors and files

Write a file

Write text, with the file closed automatically at the end of the block.

File.open("out.txt", "w") { |f| f.puts "hello" }

Official Ruby 3 documentation

More errors and files commands

All errors and files commands · Ruby 3 cheatsheet

Was this page helpful?