Created
November 10, 2021 16:59
-
-
Save fakefarm/a2dca94350397ff9acb71a84e00e5a9c to your computer and use it in GitHub Desktop.
ruby_object_to_csv.rb
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
# convert ruby objects into a csv | |
require 'csv' | |
stores = Store.all.map(&:attributes).map(&:to_options) | |
CSV.open("report.csv", "w", headers: stores.first.keys, write_headers: true) do |csv| | |
stores.each do |h| | |
csv << h.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment