Last active
November 12, 2021 09:38
-
-
Save wikiti/bd496953079a5b5740bab5e97a59afd6 to your computer and use it in GitHub Desktop.
Generate CSV file or strings with ruby
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' | |
# To a file | |
CSV.open('path/to/file.csv', 'wb') do |csv| | |
csv << ['row', 'of', 'CSV', 'data'] | |
csv << ['another', 'row'] | |
# ... | |
end | |
# To a String | |
csv_string = CSV.generate do |csv| | |
csv << ['row', 'of', 'CSV', 'data'] | |
csv << ['another', 'row'] | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment