Append row to csv file Ruby 1.9 CSV lib Append row to csv file Ruby 1.9 CSV lib ruby ruby

Append row to csv file Ruby 1.9 CSV lib


I think you can change the open to use ab:

CSV.open("t.csv", "ab") do |csv|


I will usually use the following to write to a csv file (Or any file)

File.open("filename", 'a+') {|f| f.write("datatowrite\n)}


File.open('filename', 'a'){ |outfile|  CSV::Writer.generate(outfile) do |csv|    csv << ['c1', nil, '', '"', "\r\n", 'c2']  end}