Setting end-of-line character for puts

Posted by Dom De Felice on Stack Overflow See other posts from Stack Overflow or by Dom De Felice
Published on 2010-05-18T09:40:17Z Indexed on 2010/05/18 10:51 UTC
Read the original article Hit count: 134

Filed under:

I have an array of entries I would like to print.

Being arr the array, I used just to write:

puts arr

Then I needed to use the DOS format end-of-line: \r\n, so I wrote:

arr.each { |e| print "#{e}\r\n" }

This works correctly, but I would like to know if there is a way to specify what end-of-line format to use so that I could write something like:

$eol = "\r\n"
puts arr

UPDATE

I know that puts will use the correct line-endings depending on the platform it is run on, but I need this because I will write the output to a file.

© Stack Overflow or respective owner

Related posts about ruby