0
What code allows ruby to automatically close files?
2 Answers
0
F = File.open("Example.txt",'w+')
f.puts "String of text"
f.close
you don't need f.close the file automatically closes when you terminate the program or open/create a new file
0
f = File.open("file.txt"), 'w+') {
|file| file.puts "some text"
}
this method automatically closes the file after writing to it.