Project

General

Profile

Actions

Feature #12347

closed

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

Added by ktsj (Kazuki Tsujimoto) almost 8 years ago. Updated over 7 years ago.

Status:
Closed
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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0