From: James Edward Gray II Date: 2010-07-01T00:05:26+09:00 Subject: Re: Reading String Data as a File On Jun 30, 2010, at 7:53 AM, Brian Candler wrote: > Robert Klemme wrote: >> This is an interesting point of interface design: usually it is more >> convenient to just pass a file name somewhere and that method opens >> the file (or URL) and reads the data. But from a modularity point of >> view it is generally better to pass an open IO like instance. > > Definitely. The original csv.rb in ruby 1.8 got this very badly wrong. > > The new (faster_csv) interface is capable of this, but it suffers from > missing documentation. I agree that FasterCSV's documentation isn't perfect. I'm pretty sure all of its functions are documented, but you would need to read the API like a novel to find them. I've been trying more tutorial style documentation lately, but there again it's hard to reference what you specifically want to know. I'm open to suggestions and I do take patches. > IIRR you have to do something like > > FasterCSV.new($stdin).each do |row| > p row > end That works, yes. > Since the documented "primary" interface is > FasterCSV.foreach("path/to/file.csv"), you have to dig through the code > to work out how to handle an open stream. That's mostly due to a pet peeve of mine. I often see code that slurps when foreach() would have worked fine. That's why I try to push that as a first choice. Do you think it would help if I added Wrapping an IO under the Shortcut Interface on this page? http://fastercsv.rubyforge.org/classes/FasterCSV.html James Edward Gray II