I am learning the CSV function in Ruby and although I can successfully write an array into a csv file, I can not convert that file back into an array. Test code as follows (My application just requires integers in the array)
require 'rubygems'
requires 'csv'
array = [1,2,3,4,5,6,7,8]
CSV.open('array.csv', 'w') do |csv|
csv << array
puts array.inspect
new_array = Array.new
new_array = CSV.read('array.csv', converters: :numeric)
puts new_array.inspect
end
This returns
[1, 2, 3, 4, 5, 6, 7, 8]
[]
The array.csv file is written and populated (1,2,3,4,5,6,7,8) however I just return an empty array when I read it.