Reputation: 6455
I'm trying to achieve an array that is a collection of the first element of each row achieved by reading a CSV file.
I have the following:
ids = []
CSV.foreach(filename) do |row|
ids << row[0]
end
ids
Is there any way to write this in one line? Or neater than that?
Upvotes: 0
Views: 60
Reputation: 168131
Simply do:
CSV.read(filename)
If you wanted to collect only the first column, then:
CSV.read(filename).map{|row| row[0]}
Upvotes: 0