%irb
irb(main):001:0> require 'csv'
=> true
irb(main):002:0> a = '1,2,3'
=> "1,2,3"
irb(main):003:0> CSV.parse(a, ',')
TypeError: can't convert String into Hash
from /usr/local/lib/ruby/1.9.1/csv.rb:1548:in `merge'
from /usr/local/lib/ruby/1.9.1/csv.rb:1548:in `initialize'
from /usr/local/lib/ruby/1.9.1/csv.rb:1356:in `new'
from /usr/local/lib/ruby/1.9.1/csv.rb:1356:in `parse'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
irb(main):004:0> CSV.open('test.csv', 'r', ',') { |r| puts r }
TypeError: can't convert String into Integer
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `initialize'
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `open'
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `open'
from (irb):4
from /usr/local/bin/irb:12:in `<main>'
irb(main):005:0>
Exactly like Ticket #460:
status changed from new to closed
resolution set to invalid
It means that in Ruby 1.9 the old CSV library was replaced by the FasterCSV code base. FasterCSV (now renamed to CSV in 1.9) has a slightly different interface. The call above would need to be translated to that new interface:
CSV.parse(a, :col_sep => ",")
In this case though, it would be better to leave out the separator, since it is the default.
Hope that helps.
James Edward Gray II
···
On Feb 17, 2010, at 2:47 PM, François Boone wrote:
irb(main):003:0> CSV.parse(a, ',')
TypeError: can't convert String into Hash
Exactly like Ticket #460:
status changed from new to closed
resolution set to invalid
It means that in Ruby 1.9 the old CSV library was replaced by the
FasterCSV code base. FasterCSV (now renamed to CSV in 1.9) has a
slightly different interface. The call above would need to be
translated to that new interface:
CSV.parse(a, :col_sep => ",")
In this case though, it would be better to leave out the separator,
since it is the default.
Hope that helps.
James Edward Gray II
Ok, I did not understand something!.
I have updated my ruby from 1.8.6 to 1.9.1
I used with ruby 1.8.6
FasterCSV.foreach(fichier, :col_sep =>';', :row_sep =>:auto) do |ligne|
where 'fichier' in the name of my file
and all is ok
Now, I have to change this line to use my program with ruby 1.9.1:
CSV.foreach(fichier, :col_sep => ";") do |ligne|
gives
/usr/local/lib/ruby/1.9.1/csv.rb:1329:in `initialize': can't convert
String into Integer (TypeError)
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `open'
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `open'
from aipsa2.rb:63:in `<main>'
Very little changed with CSV between 1.9.1 and 1.9.2 and I expect it to work on the lower version too.
James Edward Gray II
···
On Feb 17, 2010, at 3:57 PM, François Boone wrote:
I have updated my ruby from 1.8.6 to 1.9.1
I used with ruby 1.8.6
FasterCSV.foreach(fichier, :col_sep =>';', :row_sep =>:auto) do |ligne|
where 'fichier' in the name of my file
and all is ok
Now, I have to change this line to use my program with ruby 1.9.1:
CSV.foreach(fichier, :col_sep => ";") do |ligne|
gives
/usr/local/lib/ruby/1.9.1/csv.rb:1329:in `initialize': can't convert
String into Integer (TypeError)
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `open'
from /usr/local/lib/ruby/1.9.1/csv.rb:1329:in `open'
from aipsa2.rb:63:in `<main>'