On Feb 18, 2011, at 10:25 AM, Ronald wrote:

> Hi all,
>=20
> I am trying to generate a CSV with the code bellow:
>=20
> csv_string =3D CSV.generate(:col_sep =3D> "\t") do |csv|
>    csv << ["row", "of", "CSV", "data"]
>    csv << ["test", "a=E7=E3o"]
> end
>=20
>=20
> But when I try with Ruby 1.8.7 I get the follow error:
>=20
> ruby-1.8.7-p249/lib/ruby/1.8/csv.rb:326:in `initialize': can't convert
> Hash into String (TypeError)

That's because Ruby 1.8.7 has a different CSV library.  You'll need to =
use FasterCSV there to get the same interface.  Change your require to =
something like:

if RUBY_VERSION < "1.9"
  require "rubygems"
  require "faster_csv"
  CSV =3D FCSV
else
  require "csv"
end

> If I try with 1.9.2 I get the error:
>=20
> gerar.rb:35: invalid multibyte char (US-ASCII)
> gerar.rb:35: invalid multibyte char (US-ASCII)
> gerar.rb:35: syntax error, unexpected $end, expecting ']'
>=20
>=20
> How to fix this?

This is a non-CSV related complaint about your code.  On line 35 of the =
gerar.rb file you have used a non-ASCII character.  To do this in Ruby =
1.9, you must specify the encoding of your file.  If it's UTF-8, making =
this the first line of the file should fix it:

  # encoding:  UTF-8

Hope that helps.

James Edward Gray II=