Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/csv/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def initialize(array_of_rows, headers: nil)
#
# Also note that changes to the duplicate table will not affect the original.
def by_col
self.class.new(@table.dup).by_col!
self.class.new(@table.dup, headers: headers).by_col!
end

# :call-seq:
Expand Down Expand Up @@ -278,7 +278,7 @@ def by_col!
#
# Also note that changes to the duplicate table will not affect the original.
def by_col_or_row
self.class.new(@table.dup).by_col_or_row!
self.class.new(@table.dup, headers: headers).by_col_or_row!
end

# :call-seq:
Expand Down Expand Up @@ -316,7 +316,7 @@ def by_col_or_row!
#
# Also note that changes to the duplicate table will not affect the original.
def by_row
self.class.new(@table.dup).by_row!
self.class.new(@table.dup, headers: headers).by_row!
end

# :call-seq:
Expand Down
7 changes: 7 additions & 0 deletions test/csv/test_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def test_modes
assert_equal(:col_or_row, @table.mode)
end

def test_copy_modes_preserve_header_only_table_headers
[:by_col, :by_row, :by_col_or_row].each do |mode|
copied = @header_only_table.public_send(mode)
assert_equal(%w[A B C], copied.headers, mode)
end
end

def test_headers
assert_equal(@rows.first.headers, @table.headers)
end
Expand Down