CSV with Ruby 1.9.2 and 1.8.7

Hi all,

I am trying to generate a CSV with the code bellow:

csv_string = CSV.generate(:col_sep => "\t") do |csv|
    csv << ["row", "of", "CSV", "data"]
    csv << ["test", "ação"]
end

But when I try with Ruby 1.8.7 I get the follow error:

ruby-1.8.7-p249/lib/ruby/1.8/csv.rb:326:in `initialize': can't convert
Hash into String (TypeError)

And if I try to call the generate methos without arguments, I get a
error too

If I try with 1.9.2 I get the error:

gerar.rb:35: invalid multibyte char (US-ASCII)
gerar.rb:35: invalid multibyte char (US-ASCII)
gerar.rb:35: syntax error, unexpected $end, expecting ']'

How to fix this?

···

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

First and possibly most important, the CSV implementation is completely
different on 1.8 and 1.9, and I'm not sure that the original 1.8.7 version
supports Unicode at all. So while the TypeError is a little bit cryptic,
I'm not sure I can provide a better explanation.

The error under 1.9.2 is because you didn't specify an :encoding in your
call to generate. This works under 1.9.2 on my machine:
csv_string = CSV.generate(:col_sep => "\t", :encoding => "UTF-8") do |csv|
   csv << ["row", "of", "CSV", "data"]
   csv << ["test", "ação"]
end

···

On Fri, Feb 18, 2011 at 5:34 PM, Ronald R. <ronaldrails@gmail.com> wrote:

Hi all,

I am trying to generate a CSV with the code bellow:

csv_string = CSV.generate(:col_sep => "\t") do |csv|
   csv << ["row", "of", "CSV", "data"]
   csv << ["test", "ação"]
end

But when I try with Ruby 1.8.7 I get the follow error:

ruby-1.8.7-p249/lib/ruby/1.8/csv.rb:326:in `initialize': can't convert
Hash into String (TypeError)

And if I try to call the generate methos without arguments, I get a
error too

If I try with 1.9.2 I get the error:

gerar.rb:35: invalid multibyte char (US-ASCII)
gerar.rb:35: invalid multibyte char (US-ASCII)
gerar.rb:35: syntax error, unexpected $end, expecting ']'

How to fix this?

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

Hi,

I tried set UTF-8 like you, but didnt works with 1.9.2. I got the same
error.

I tried with 1.9.2-head and 1.9.2-preview1

···

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

First and possibly most important, theCSVimplementation is completely
different on 1.8 and 1.9, and I'm not sure that the original1.8.7version
supports Unicode at all. So while the TypeError is a little bit cryptic,
I'm not sure I can provide a better explanation.

The error under1.9.2is because you didn't specify an :encoding in your
call to generate. This works under1.9.2on my machine:
csv_string =CSV.generate(:col_sep => "\t", :encoding => "UTF-8") do |csv|
csv<< ["row", "of", "CSV", "data"]
csv<< ["test", "ação"]
end

> Hi all,

> I am trying to generate aCSVwith the code bellow:

> csv_string =CSV.generate(:col_sep => "\t") do |csv|
> csv<< ["row", "of", "CSV", "data"]
> csv<< ["test", "ação"]
> end

> But when I try withRuby1.8.7I get the follow error:

>ruby-1.8.7-p249/lib/ruby/1.8/csv.rb:326:in `initialize': can't convert
> Hash into String (TypeError)

> And if I try to call the generate methos without arguments, I get a

Hi,

I tried set UTF-8 like you, but didnt works with 1.9.2. I got the same
error.

I tried with 1.9.2-head and 1.9.2-preview1

···

On 18 fev, 14:49, Chris Kottom <ch...@chriskottom.com> wrote:

On Fri, Feb 18, 2011 at 5:34 PM, Ronald R. <ronaldra...@gmail.com> wrote:

> error too

> If I try with1.9.2I get the error:

> gerar.rb:35: invalid multibyte char (US-ASCII)
> gerar.rb:35: invalid multibyte char (US-ASCII)
> gerar.rb:35: syntax error, unexpected $end, expecting ']'

> How to fix this?

> --
> Posted viahttp://www.ruby-forum.com/.