Last active
October 1, 2019 18:38
-
-
Save nmenag/647824228f1138b2bfb0db4b77a3f552 to your computer and use it in GitHub Desktop.
Script for save the hash data to CSV file
This file contains hidden or 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
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