Writing CSV file from Array

Discussion in 'Ruby' started by john_urban, Jun 3, 2012.

  1. john_urban

    john_urban Guest

    I need to put double quotes around String objects from the array, but
    not around other types of objects. :force_quotes puts double quotes
    around every field. I don't want that. What is the best way to do
    this? For example...

    a = [["joe","cool",19,1000], ["mary","jane",20,5000]]

    CSV.open("new_file.csv", "w", {:force_quotes=>true}) do |csv| a.each
    do |r| csv << r end end

    gives us this in the csv file:


    I need this:

    john_urban, Jun 3, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.