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)
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 = FCSV
else
require "csv"
end
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: