Add a new line in file?
I want to add a new line after a string is inserted.
My current code looks like this:
File.open(filename, 'a') do |file|
file.write @string
end
How could I add a new line after th开发者_Go百科e string is inserted?
Use IO#puts.
file.puts @string
file.write "\n"
In case if you can't use IO#puts:
file.write "text#{$/}"
where $/
represents OS-dependent new line separator.
精彩评论