Skip to content

Instantly share code, notes, and snippets.

@DeltaWhy
Last active December 16, 2015 02:39
Show Gist options
  • Save DeltaWhy/5364057 to your computer and use it in GitHub Desktop.
Save DeltaWhy/5364057 to your computer and use it in GitHub Desktop.
Turn a CSV file (where the first line contains the column names) into an array of hashes
def parse_csv
csv = CSV.parse(STDIN.read)
columns = csv[0].map(&:to_sym)
csv.delete_at(0)
csv.map do |row|
Hash[columns.zip(row)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment