ruby - Setting end-of-line character for puts -


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

arr array, I just used to write:

  arrow  

then I need to use DOS format end line: \ r \ N, so I wrote:

  arr.each {| E Print "# {E} \ r \ n"}  

This works correctly, but I would like to know whether there is a way to specify which type of end- The off-line format should be used so that I can write something like this:

  $ eol = "\ r \ n" puts the AR  

UPDATE 1

I know that puts will use the correct line-ending running on that platform, but I need it because I Output file in Not write.

Update 2 As the mark has been suggested, setting $ \ is useful, however it is only print For example,

  irb (main): 001: 0> A = [1, 2, 3] = & gt; [1, 2, 3] IRB (Main): 002: 0> $ \ = "\ R \ n" = & gt; "\ R \ n" irb (main): 003: 0> A 123 = & gt; Print Zero Erb (Main): 004: 0> One puts 1 2 3 & gt; Zero  

print prints all array items on one line and then adds $ \ , while I say Want to behave: Add $ \ after every item of the array.
What Array # is this possible without using each?

Ruby variable $ \ to print and write calls to write The record separator will set:

  & gt; & Gt; $ \ = '!!!' = & Gt; "!!!" & Gt; & Gt; Hi the print 'Hi' !!! = & Gt; Alternatively you can refer to  $ \   $ OUTPUT_RECORD_SEPARATOR  if you import the module. 


is equal to kernel # puts STDOUT.puts ; And IO.puts "after each element a new line that does not end up with a new line sequence already". So you are out of luck with net for arrays puts However, $, is a separator string output from the variable parameter which is kernel # print Suck as and Array # join . So if you can call print arr.join , then this could be the best solution for you:

  & gt; & Gt; [1,2,3] .join => "123" & gt; & Gt; $, = '---' = & gt; "---" & gt; & Gt; [1,2,3] .join => "1 --- 2 --- 3" & gt; & Gt; $ \ = '!!!' = & Gt; "!!!" & Gt; & Gt; Print [1,2,3] .Join 1 --- 2 --- 3 !!! = & Gt; Void  

Comments