I have this, which will have another 3 or 4 variables appended:
name, theme = row[0], row[1]
Is there a shortcut to the code on the right? I tried:
name, theme = row
But then name returned the entire row, and didn’t seem to work in this case.
I am using CSV.foreach, and the above didn’t work when I added {headers: true}:
CSV.foreach('file.csv', {headers: true}) do |row|
name, theme = row
name # returns entire row in string
end
Just in case your row is not array, try calling
or
If it doesn’t have to_a method, yo’ve to define it.