这可行,但由于某种原因缺少逗号。data
被插入为
GAURISH SHARMA
97
69
69
975
PASS
每个值都写在新行中。我想知道逗号去哪儿了?还是必须手动插入?
我正在尝试使用以下代码编写哈希值
CSV.open("resultdata.csv", "a") do |csv|
h.each do |key, value|
csv << value
end
end
这是h
哈希的内容
{:name=>"GAURISH SHARMA",
:ca=>"97",
:cb=>"69",
:ba_lab=>"69",
:bb_lab=>"69",
:grand_total=>"975",
:result=>"PASS"}
此代码看起来正确,但在运行此代码时,会生成以下错误:
/home/gaurish/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/csv.rb:1729:in `<<': undefined method `map' for "GAURISH SHARMA":String (NoMethodError)
from /home/gaurish/Dropbox/code/projects/ra/result.rb:35:in `block (2 levels) in <main>'
from /home/gaurish/Dropbox/code/projects/ra/result.rb:34:in `each'
from /home/gaurish/Dropbox/code/projects/ra/result.rb:34:in `block in <main>'
from /home/gaurish/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/csv.rb:1354:in `open'
from /home/gaurish/Dropbox/code/projects/ra/result.rb:33:in `<main>'
知道这里有什么问题吗?