Created
October 10, 2012 16:59
-
-
Save chicks/3866904 to your computer and use it in GitHub Desktop.
Convert an array of hashes into a CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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