What is Ruby 1.9 standard CSV library?

后端 未结 2 1794
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 08:57

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.         


        
相关标签:
2条回答
  • 2020-12-01 09:24

    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.

    0 讨论(0)
  • 2020-12-01 09:27

    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
    
    0 讨论(0)
提交回复
热议问题