8000 [ruby/csv] Make CSV::Row#dup return a usable Row (#108) · github/ruby@b219cd5 · GitHub
[go: up one dir, main page]

Skip to content

Commit b219cd5

Browse files
fastjamesnobu
authored andcommitted
[ruby/csv] Make CSV::Row#dup return a usable Row (#108)
* Make CSV::Row#dup return a usable Row Previously, calling `dup` on a `CSV::Row` object yielded an object whose copy was too shallow. Changing the clone's fields would also change the fields on the source. This change makes the clone more distinct from the source, so that changes can be made to its fields without affecting the source. * Simplify ruby/csv@64a1ea06fc
1 parent 9141aae commit b219cd5

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/csv/row.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def initialize(headers, fields, header_row = false)
5050

5151
def initialize_copy(other)
5252
super
53-
@row = @row.dup
53+
@row = @row.collect(&:dup)
5454
end
5555

5656
# Returns +true+ if this is a header row.

test/csv/test_row.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ def test_dig_cell_no_dig
425425
def test_dup
426426
row = CSV::Row.new(["A"], ["foo"])
427427
dupped_row = row.dup
428+
dupped_row["A"] = "bar"
429+
assert_equal(["foo", "bar"],
430+
[row["A"], dupped_row["A"]])
428431
dupped_row.delete("A")
429432
assert_equal(["foo", nil],
430433
[row["A"], dupped_row["A"]])

0 commit comments

Comments
 (0)
0