For writing text files; especially line by line, it’s perfectly acceptable to use
puts. But, be warned that this will append a line break after the data being written. This behaviour is not desirable when working with binary files, when IO::write is a better choice to avoid unwanted line break characters.
For example:
file = File.new('temp.file', 'w+')
file.sync = true
while data = get_data
file.write data
end
file.rewind
August 28, 2010 at 1:25 pm
[...] reading Take care when writing to files using puts on my old blog… Categories [...]