Skip to content

Instantly share code, notes, and snippets.

@chicks
Created October 10, 2012 16:59
Show Gist options
  • Save chicks/3866904 to your computer and use it in GitHub Desktop.
Save chicks/3866904 to your computer and use it in GitHub Desktop.
Convert an array of hashes into a CSV
array_of_hashes = [{:a => 1, :b => 2}, {:a => 3, :b => 4}]
csv = array_of_hashes.inject([]) {|csv, hash| csv << hash.values.join(",")}
csv.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment