Closed Jee-El closed 2 years ago
Could you paste main.rb
and attach event_attendees.csv
here for easy to refer?
main.rb
require 'csv'
# it returns true on the second call of #eof? as expected only if
# I comment the 4th line, starting from the line below this
puts 'csv'
csv = CSV.open('event_attendees.csv')
puts "pos : #{csv.pos}" # expecting 0
puts "eof? : #{csv.eof?}" # expecting false
csv.read
puts "pos : #{csv.pos}" # expecting 1814
puts "eof? : #{csv.eof?}" # expecting true
puts
# no issue when using File.open
puts 'File'
file = File.open('event_attendees.csv')
puts "pos : #{file.pos}" # expecting 0
puts "eof? : #{file.eof?}" # expecting false
file.read
puts "pos : #{file.pos}" # expecting 1814
puts "eof? : #{file.eof?}" # expecting true
Thanks. I've fixed this.
Ruby version : 3.1.2p20, as well as 2.7.4p191 (replit) Steps to reproduce the issue(?) :
CSV.open('file.csv')
#pos
on it, it returns 0#eof?
on it, it returns false#read
on it#pos
on it, it returns the last position#eof?
on it, it returns false when it should be trueIt seems to return true if
#eof?
isn't called before reading the file. (i.e: omit the third line above)Demonstration : https://replit.com/@Jee-El/Ruby-CSV-eof-issue?v=1