Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我无法获得标题。没有错误发生。我怎样才能正确地得到它?
数据:
"A","B","C" "1","2","3"
红宝石:
require "csv" table = CSV.read("filename", :headers => true) puts table[0] # "1","2","3" puts table[headers] # Nothing happens.
尝试table.headers:
table.headers
irb(main):006:0> table.headers => ["A", "B", "C"]
你是如何运行这段代码的?table[headers]应该返回一个错误:
table[headers]
irb(main):008:0> table[headers] NameError: undefined local variable or method `headers' for main:Object from (irb):8 from /usr/bin/irb:12:in `<main>'