Skip to content

Instantly share code, notes, and snippets.

@flakyfilibuster
Created October 18, 2012 07:54
Show Gist options
  • Save flakyfilibuster/3910342 to your computer and use it in GitHub Desktop.
Save flakyfilibuster/3910342 to your computer and use it in GitHub Desktop.
CSV methods for easy csv to array and array to csv conversion
Peggie Bernier (598)-885-3990 georgianna.casper@emardvolkman.org
Ines Roberts (717)-629-5254 alanis.hane@bayer.com
Carley Luettgen (153)-754-3308 jeramy_terry@kerluke.org
Evie Bashirian (684)-662-7552 herminia_jewe@schumm.biz
peggie bernier (598)885-3990 georgianna.casper@emardvolkman.org
ines roberts 717.629.5254 alanis.hane@bayer.com
carley Luettgen 153.754.3308 jeramy_terry@kerluke.org
Evie Bashirian 684.662.7552 herminia_jewe@schumm.biz
require 'csv'
def array_to_csv(output_file_name, array)
CSV.open(output_file_name,'w') do |csv|
array.each {|line| csv << line}
end
end
def csv_to_array(file_name)
array = []
CSV.foreach(file_name) {|line| array << line}
array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment