Permalink
Browse files

#dup and #clone do deep copy of table contents.

  • Loading branch information...
1 parent 9b4e27f commit b5d5796ab73ee7f6f939001ffa743fc51398ffc6 @lukaso lukaso committed Aug 19, 2012
Showing with 19 additions and 0 deletions.
  1. +5 −0 lib/turnip/table.rb
  2. +14 −0 spec/table_spec.rb
View
@@ -9,6 +9,11 @@ def initialize(raw)
@raw = raw
end
+ def initialize_copy(other)
+ super
+ @raw = Marshal.load(Marshal.dump(other.raw))
+ end
+
def headers
raw.first
end
View
@@ -76,4 +76,18 @@
table.map(&:first).should == ['moo', 'quox']
end
end
+
+ describe '#dup and #clone' do
+ it "makes a deep copy when calling #dup" do
+ new_table = table.dup
+ new_table.raw[0][0] = 'blegga'
+ table.raw[0][0].should == 'foo'
+ end
+
+ it "makes a deep copy when calling #clone" do
+ new_table = table.dup
+ new_table.raw[0][0] = 'blegga'
+ table.raw[0][0].should == 'foo'
+ end
+ end
end

0 comments on commit b5d5796

Please sign in to comment.