ruby write to csv code example
Example 1: ruby create CSV
CSV.open("file.csv", "a+") do |csv|
csv << ["cow", "3","2500"]
end
Example 2: save to csv ruby
CSV.open("filename.csv", "wb") do |row|
row << ["a", "b", "c"]
end
Example 3: ruby write to 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