From: Robert Klemme Date: 2013-02-21T22:14:04+09:00 Subject: Re: Select "columns" from multidimensional array? On Thu, Feb 21, 2013 at 1:40 PM, Joel Pearson wrote: > I thought I could avoid the issue of splitting the data into multiple > outputs by creating copies of the class, but apparently I was wrong: > > irb(main):002:0> m = RubyExcel.new.load [['a','b']] > => columns: 2, rows: 1, values: 2 > > irb(main):003:0> a = m.clone > > irb(main):004:0> a['A1'] = nil > > irb(main):005:0> puts a > b > > irb(main):006:0> puts m > b > > What am I doing wrong? Is @data inside m not being duplicated along with > the class instance? #clone and #dup are _always_ shallow copies. If you want to change that you need to override them, e.g. class Excel def dup super.tap do |copy| %w{@table foo}.each {|iv| copy.instance_variable_set(iv, instance_variable_get(iv).dup)} end end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/