After being able to open a CSV file and iterate through it, it’s not possible to go through it again once its
@traversed property is set to true, given that
#next returns false until the file is loaded again.
I reviewed Crystal’s csv’s source code and noticed that recently the
#rewind method was removed from many iterators, but It might have broken the CSV object manipulation. Now I don’t see any functionality to traverse CSV object many times. I have to load the file again.
Am I missing something?
Here’s an example of the problem:
require "csv" File.open(filename) do |infile| csv_rows = CSV.new(infile, header = true) csv_rows.each do |row| print row # prints every row object end csv_rows.each do |row| print row # never reaches here end end