-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
James Edward G. II wrote:
File.open(“example.csv”, “w”) do |csv|
“1,2,3\n”
CSV.open(“example.csv”, “r”) do |row| # “r” required
?> p row # we get rows, not the file object
end
[“1”, “2”, “3”]
[“a”, “b”, “c”]
=> nil
Of course, if you open in a writing mode, you do get a file like
object. It’s inconsistent.
I can understand your frustration about this point. When I wrote csv.rb
at first, I thought all csv users would do the following when I define
reader style.
CSV.open(“filename.csv”, “r”) do |reader|
reader.each do |row|
…do something…
end
end
Why don’t we just write like this;
CSV.open(“filename.csv”, “r”) do |row|
…do something…
end
I know you are considering that IO-ish methods are important. But I
don’t think CSV object should handle IO methods like fcntl, fileno,
seek, tell, tty?, and so on. Would you please tell me typical and
pragmatic examples of reader style, except ‘each’?
I’m confused about why CSV does this, since it offers the foreach()
method, which normally fills this role.
foreach and readlines are added recently from IO. Now I think it was a
bad choice though…
Other CSV oddities (my opinion):
Thanks!
- I always have to think, “Now do I want the *_line() method or the
*_row() method here…”
Users don’t need to use *_line and *_row methods I think. When do you
use generate_line?
- Most methods take a field separator and a row separator, but
foreach() and readlines() only take the row separator.
See IO.foreach and IO.readlines. But as I wrote above, CSV should not
have these methods…
- I have to set a field separator when I really just want to set a row
separator.
csv.rb in svn repository supports pseudo-keyword-like-method-argument
style. I’ll merge it ruby’s csv repository before the next release.
http://dev.ctor.org/csv/browser/trunk/lib/csv.rb
I defined keywords :fs and :rs but it should be :col_sep and :row_sep
in conformity with faster_csv.
- A method called “generate_line()” doesn’t involve a line ending.
Do not use it.
At least users rarely use it I think.
I hope that
csv.rb’s open + read + block does not work as you expected
is the only and the big frustrated point of csv.rb (…if csv.rb is
enough faster 
- We could drop compatibility and rename FasterCSV to CSV. This way
people get all the good stuff where they expect it. However, this would
Can you please explain what are “good”? I’ll introduce those features
into csv.rb.
Here’s a selection of some features from my CHANGELOG that I am not
aware of in CSV:
Thanks. I’ll look into this. I hope those features are pluggable into
csv.rb and other modules like DBI, spreadsheet related things, HTML
table formatters, etc. I think some of these features are table
specific, not CSV.
Regards,
// NaHi
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
iQEVAwUBRIOAux9L2jg5EEGlAQLJ7Qf/RTK7xk0KDqlqJ8vuDHY9cfuQLGJ+0Re2
rNwZjSHlXiZ/0bqlJ2ZXcsAFiK1BWeigfxvZbQJg5n3rqXLaYhYSZ0bsMN8q7CrM
L2C+ExEWQwZqKMWfOXFmIgCV6ynOR+FXdwA4hP4BcYY9xaidYR86wRCT/oBG5cvg
FYXSSFO74y4265mDggPfphM4vUqWaDz6kv0J4oX8X1pQ/aKao9tiAzFyr7RcyQXR
TCD8koK1IAqstQ0AEjNvTVJUkThBs00JJYuLjWMCZSFbZzUX6fO0Bo9S+1V5B1oX
JI5+oi4hqYWO5yXM4Rjp+wU5lcLuT9KWgEimGhdifLj05h/N90q/1Q==
=IbUC
-----END PGP SIGNATURE-----