What is Ruby 1.9 standard CSV library?

谁说胖子不能爱 提交于 2019-11-26 13:50:09

问题


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.


回答1:


Ruby 1.9 has adopted FasterCSV as its built-in CSV library. However, it's in the standard library rather than Ruby 1.9's core, so you need to manually require it in your application.

After adding a

require 'csv'

to your code, you can then do things such as

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

See Ruby 1.9's standard library CSV documentation for information on using the library.




回答2:


See how I solved this problem!

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


来源:https://stackoverflow.com/questions/5011395/what-is-ruby-1-9-standard-csv-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!