Created
October 18, 2012 07:54
-
-
Save flakyfilibuster/3910342 to your computer and use it in GitHub Desktop.
CSV methods for easy csv to array and array to csv conversion
This file contains 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
Peggie | Bernier | (598)-885-3990 | [email protected] | |
---|---|---|---|---|
Ines | Roberts | (717)-629-5254 | [email protected] | |
Carley | Luettgen | (153)-754-3308 | [email protected] | |
Evie | Bashirian | (684)-662-7552 | [email protected] |
This file contains 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
peggie | bernier | (598)885-3990 | [email protected] | |
---|---|---|---|---|
ines | roberts | 717.629.5254 | [email protected] | |
carley | Luettgen | 153.754.3308 | [email protected] | |
Evie | Bashirian | 684.662.7552 | [email protected] |
This file contains 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' | |
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