Repeat CSV.generate_line ruby ​​1.8.7 behavior in ruby ​​1.9.2

ruby 1.9 now uses quickcsv, but how can I replicate the generate_line ruby ​​1.8.7 behavior?

ruby-1.8.7-p334 :010 > require 'csv'
 => true
ruby-1.8.7-p334 :010 > CSV.generate_line(["ab","cd"], "\t")
 => "ab\tcd"

ruby-1.9.2-p180 :002 > require 'csv'
 => true
ruby-1.9.2-p180 :007 > CSV.generate_line(["ab","cd"], :row_sep => ?\t)
 => "ab,cd\t"

Notice what \tis between the two elements of the array in ruby ​​1.8.7 and finally in1.9.2

+3
source share
2 answers

You should use col_sep instead. row_sep - line separator:

CSV.generate_line(["ab","cd"], :col_sep => ?\t)
=> "ab\tcd\n"

or

CSV.generate_line(["ab","cd"], :col_sep => ?\t, :row_sep => '')
=> "ab\tcd"

More information and additional parameters can be found in the documentation .

+3
source

CSV.generate_line (['a', 'b', 's'] ,: col_sep => "\ t")

+1
source

All Articles