System new line separator in Ruby
问题 How can I determine new line separator used by OS (LF, CR/LF or other), in Ruby? 回答1: Not sure if there is a direct solution to get the type of newline based on OS, but there is the $/ variable that holds the "input record separator". By default this will be "\n". (Documentation here) You can detect the OS and then set $/ to the "correct" value. To detect OS: puts RUBY_PLATFORM # => 'i386-linux' require 'rbconfig' puts Config::CONFIG['target_cpu'] # => 'i386' puts Config::CONFIG['target_os']