Posted By

plexus on 07/27/07


Tagged

array csv


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mabridge
jhenry
webstic
bangarang3


Array#to_csv


 / Published in: Ruby
 

Ruby's CSV is a nice library, but it needs some sugar.

  1. require 'CSV'
  2.  
  3. class Array
  4. def to_csv
  5. str=''
  6. CSV::Writer.generate(str) do |csv|
  7. self.each do |r|
  8. csv << r
  9. end
  10. end
  11. str
  12. end
  13. end

Report this snippet  

You need to login to post a comment.