这有效:
require 'csv'
file = CSV.open(filename)
puts file.shift
这不会:
require 'csv'
file = CSV.open(filename, :headers=>true)
puts file.shift
我得到:
C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/1.9.1/csv.rb:2177:in `convert_field
s': undefined method `with_index' for IronRuby.Builtins.Enumerator:Enumerator (N
oMethodError)
from C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/1.9.1/csv.rb:2218:in `
parse_headers'
from C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/1.9.1/csv.rb:1918:in `
shift'
from C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/1.9.1/csv.rb:1818:in `
loop'
from C:/Program Files (x86)/IronRuby 1.1/Lib/ruby/1.9.1/csv.rb:1818:in `
shift'
from C:/myproject/myproject/myproject/Program.rb:3
我正在使用 Ironruby 1.1.3
我正在寻找正确的语法来获得带有 headers 选项的单行。