Skip to content

Instantly share code, notes, and snippets.

@ammaaim
Last active August 29, 2015 14:09
Show Gist options
  • Save ammaaim/bd830b04ec291885564c to your computer and use it in GitHub Desktop.
Save ammaaim/bd830b04ec291885564c to your computer and use it in GitHub Desktop.
ruby csv example
# in excel: file->import->CSV file
require 'csv'
# write csv
CSV.open("file.csv", "wb") do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ...
end
# read csv
data = CSV.read("file.csv")
print data
#or
CSV.foreach("file.csv") do |row|
print row
puts ""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment