What is Ruby 1.9 standard CSV library?

When I try the FasterCSV gem on my application I get this error:

Please switch to Ruby 1.9's standard
CSV library.  It's FasterCSV plus
support for Ruby 1.9's m17n encoding
engine.

By the way, I'm using Rails 3, Ruby 1.9.2, and Rubygems 1.4.

Can someone explain to me please how to use the standard CSV library for Ruby 1.9. I don't have any idea at all because I'm very new to Rails.

29799 次浏览

Ruby 1.9已经采用 FasterCSV 作为其内置的 CSV 库。但是,它位于标准库中,而不是 Ruby 1.9的核心,因此您需要在应用程序中手动要求使用它。

After adding a

require 'csv'

然后,您可以执行以下操作

CSV.parse("this,is,my,data")

有关使用该库的信息,请参见 Ruby 1.9的标准库 CSV 文档

看看我是怎么解决这个问题的!

require 'fastercsv'
require 'csv'


secrecy_levels_array = [['SUPERSECRET', 'Supersecret Data', "Tell No One"],
['SEMISECRET', 'Semisecret Data', 'Tell Some People'],
['UNSECRET', 'Unsecret Data', 'Tell Everyone']]


puts '\n'
secrecy_levels_array.each do |line|
puts line.to_csv
end