I have a text file with path name file
, and some content string
that I want to append to it. I want to do something close to
File.open(file, "a"){|io| io.puts(string)}
but if the original content of the file does not end with an endline character $/
, I want to insert one before string
. What is the most effective way to do this?