Project

General

Profile

Feature #12347

[PATCH] Make CSV::Row#each etc. return Enumerator when no block given

Added by ktsj (Kazuki Tsujimoto) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:75346]

Description

I propose to make following methods return Enumerator when no block given.

  • CSV::Row#each
  • CSV::Row#delete_if
  • CSV::Table#each
  • CSV::Table#delete_if

I think that the behavior without block is undefined (and several methods raise error in such a case as follows),
so it will not break compatibility.

$ ruby -rcsv -e 'CSV::Table.new([CSV::Row.new(%w{A}, [1])]).by_col.each'
/usr/local/ruby-2.3/lib/ruby/2.3.0/csv.rb:850:in `block in each': undefined method `[]' for nil:NilClass (NoMethodError)
        from /usr/local/ruby-2.3/lib/ruby/2.3.0/csv.rb:850:in `each'
        from /usr/local/ruby-2.3/lib/ruby/2.3.0/csv.rb:850:in `each'
        from -e:1:in `<main>'

Files

History

Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • Assignee set to JEG2 (James Gray)
  • Status changed from Open to Assigned

Updated by ktsj (Kazuki Tsujimoto) about 3 years ago

I will commit it in a month.
Let me know if you have any concerns.

Updated by ktsj (Kazuki Tsujimoto) about 3 years ago

  • Status changed from Assigned to Closed

committed at r56083.

Also available in: Atom PDF