我有這個,這將有另外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