Skip to content

Instantly share code, notes, and snippets.

@fakefarm
Created November 10, 2021 16:59
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 fakefarm/a2dca94350397ff9acb71a84e00e5a9c to your computer and use it in GitHub Desktop.
Save fakefarm/a2dca94350397ff9acb71a84e00e5a9c to your computer and use it in GitHub Desktop.
ruby_object_to_csv.rb
# 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