Skip to content

Commit

Permalink
Support implicit Row <-> Array conversion
Browse files Browse the repository at this point in the history
Ruby: [Bug #10013] [ruby-core:63582]

Reported by Dawid Janczak. Thanks!!!
  • Loading branch information
kou committed Mar 10, 2018
1 parent ba560e4 commit 71d66af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/csv/row.rb
Expand Up @@ -335,6 +335,8 @@ def to_h
end
alias_method :to_hash, :to_h

alias_method :to_ary, :to_a

#
# Returns the row as a CSV String. Headers are not used. Equivalent to:
#
Expand Down
9 changes: 9 additions & 0 deletions test/csv/test_table.rb
Expand Up @@ -261,6 +261,15 @@ def test_each
@table.each { |row| assert_instance_of(CSV::Row, row) }
end

def test_each_split
yielded_values = []
@table.each do |column1, column2, column3|
yielded_values << [column1, column2, column3]
end
assert_equal(@rows.collect(&:to_a),
yielded_values)
end

def test_enumerable
assert_equal( @rows.values_at(0, 2),
@table.select { |row| (row["B"] % 2).zero? } )
Expand Down

0 comments on commit 71d66af

Please sign in to comment.