Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Ruby have a constant for cross-platform EOL somewhere?

Tags:

ruby

I need to format a String that ends with a newline. I'd just add a "\n", but I want this to work on Windows too. Many languages have a constant that provides the appropriate CR/LF/CRLF sequence according to the platform, but I can't seem to find anything in Ruby. Does it exist?

like image 918
d11wtq Avatar asked Oct 10 '12 12:10

d11wtq


1 Answers

Ruby's got four (!)

p $/
p $-0
require 'English'
p $RS
p $INPUT_RECORD_SEPARATOR

Using IO#puts (= File#puts) will take care of the proper EOL, no need to set it manually.

like image 109
steenslag Avatar answered Nov 17 '22 11:11

steenslag