I want to read data records from a non-seekable stream in Ruby. I want to leave it up to the user whether the current record should be skipped or read. Usually you would include Enumerable
and provide the necessary methods for it to have an iterator in Ruby, but in my case data can be skipped and only one iteration is possible, so I'm not sure what I should do.
Which one would you prefer?
while record = foo.next
if bar
foo.read
else
foo.skip
end
end
or
foo.each do |record|
if bar
foo.read
else
foo.skip
end
end