Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Tim Morgan http://timmorgan.org

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Make a list into a line suitable for a CSV file in Ruby

Formats a list/array as a string suitable for one row of a CSV file

   1  
   2  def comma_separate(items)
   3    items.map! do |item|
   4      if item.is_a?(String) and item =~ /[",]/
   5        '"' + item.gsub(/"/, '""') + '"'
   6      else
   7        item
   8      end
   9    end
  10    items.join(',')
  11  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS