Add a new line in file?

Viewed 84425

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?

3 Answers

In case if you can't use IO#puts:

file.write "text#{$/}"

where $/ represents OS-dependent new line separator.

Related