Format csv in ruby so that string columns have double-quotes, but numerical columns don't

457 views Asked by At

I am trying to output a CSV file in ruby, that looks like this:

"numeric_column","string_column"
1,"string1"
2,"long string"

I could only find a way to have no quotes at all or quotes also on the numeric column.

My code looks like this now:

CSV.open("file.csv", "wb", force_quotes: true, headers: ['id', 'name'], write_headers: true) do |csv|
    csv << [id, name]
end
0

There are 0 answers