What code allows ruby to automatically close files? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What code allows ruby to automatically close files?

4th Mar 2017, 9:19 AM
Emmanuel Nuotah
2 Respostas
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
4th Mar 2017, 11:52 PM
Jan Andersson
Jan Andersson - avatar
0
f = File.open("file.txt"), 'w+') { |file| file.puts "some text" } this method automatically closes the file after writing to it.
16th Mar 2017, 12:22 PM
iRonnie16
iRonnie16 - avatar