I am perplexed by CSV.open. In IO and File, open returns something that 
quacks like an IO object. You can then call gets, puts, read, write and 
so on. The CSV open seems to return an array (or gives you a row at a 
time). This makes it very hard to write code that can take advantage of 
duck typing, e.g.

def get_batch(f, count)
  lines = nil
  count.times do
     break unless line = f.gets
     (lines ||= []) << line
  end
  lines
end

get_batch(File.open("foo"), 40000) # No problem
get_batch(CSV.open("foo", "r"), 40000) # Error

I wonder why it was not patterned more closely on IO? Any thoughts?

-- 
Posted via http://www.ruby-forum.com/.