From: mame@... Date: 2018-03-08T07:33:43+00:00 Subject: [ruby-core:86027] [Ruby trunk Bug#10013] [CSV] Yielding all elements from a row Issue #10013 has been updated by mame (Yusuke Endoh). Assignee changed from JEG2 (James Gray) to kou (Kouhei Sutou) @kou, could you check this ticket? ---------------------------------------- Bug #10013: [CSV] Yielding all elements from a row https://bugs.ruby-lang.org/issues/10013#change-70887 * Author: Gat (Dawid Janczak) * Status: Assigned * Priority: Normal * Assignee: kou (Kouhei Sutou) * Target version: * ruby -v: ruby 2.2.0dev (2014-07-06 trunk 46722) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- Let's say I have the following CSV file: col1,col2,col3 1,2,3 4,5,6 (...) I want to iterate over values yielding them to a block. I can do that like this: `CSV.foreach('file.csv') { |col1, col2, col3| print col2 + " " } # => "col2 2 5"` This works fine, but I would like to skip the headers: `CSV.foreach('file.csv', headers: true) { |col1, col2, col3| print col2 + " " } # => NoMethodError` CSV yields rows as arrays if headers option is not specified and destructuring works fine. When headers option is specified however, CSV::Row objects are yielded instead and destructuring fails. It would be nice to have both scenarios working in the same manner, but I don't know how to approach this. Calling to_a on yielded row (https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1731) worked, but obviously this would break when people actually expect CSV::Row instance. Any ideas? -- https://bugs.ruby-lang.org/ Unsubscribe: