Skip to content

Instantly share code, notes, and snippets.

@nmenag
Last active October 1, 2019 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmenag/647824228f1138b2bfb0db4b77a3f552 to your computer and use it in GitHub Desktop.
Save nmenag/647824228f1138b2bfb0db4b77a3f552 to your computer and use it in GitHub Desktop.
Script for save the hash data to CSV file
require 'csv'
data = [{'a' => 'aaaa', 'b' => 'bbbb'}]
column_names = data.first.keys
s=CSV.generate do |csv|
csv << column_names
data.each do |x|
csv << x.values
end
end
File.write('the_file.csv', s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment