我有这个,这将有另外3个或4个变量附加:这是红宝石的捷径吗?
name, theme = row[0], row[1]
是否有一个快捷方式到右边的代码?我试过了:
name, theme = row
但是然后名字返回整行,并且在这种情况下似乎不起作用。
我使用CSV.foreach,当我加入{头:真}:以上没有工作
CSV.foreach('file.csv', {headers: true}) do |row|
name, theme = row
name # returns entire row in string
end
你确定吗?你使用哪个ruby版本? – 2012-08-15 09:54:56
是的,我确定。我已经更新了我的答案,为什么。 – 2012-08-15 09:56:49
显然,在你的情况下,行不是真正的数组。 – 2012-08-15 10:00:33