I am new in ruby so please forgive the noobishness.
I have a CSV with two columns. One for animal name and one for animal type. I have a hash with all the keys being
If you want column headers and you have multiple hashes:
require 'csv' hashes = [{'a' => 'aaaa', 'b' => 'bbbb'}] column_names = hashes.first.keys s=CSV.generate do |csv| csv << column_names hashes.each do |x| csv << x.values end end File.write('the_file.csv', s)
(tested on Ruby 1.9.3-p429)