Add a new line in file?
RubyRuby Problem Overview
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 the string is inserted?
Ruby Solutions
Solution 1 - Ruby
Use IO#puts.
file.puts @string
Solution 2 - Ruby
file.write "\n"
Solution 3 - Ruby
In case if you can't use IO#puts:
file.write "text#{$/}"
where $/
represents OS-dependent new line separator.