open file block : Open a File « File Directory « Ruby
- Ruby
- File Directory
- Open a File
open file block
# Put some stuff into a file.
open('sample_file', 'w') do |f|
f.write("This is line one.\nThis is line two.")
end
open('sample_file').each { |x| p x }
# "This is line one.\n"
# "This is line two."
Related examples in the same category