From: Robert Klemme Date: 2009-10-08T16:55:58+09:00 Subject: Re: How to do explicit copy 2009/10/8 rickyr : > On Oct 6, 10:50 pm, Patrick Okui wrote: >> On Oct 6, 2009, at 6:45 PM, rickyr wrote: >> >> > y = x >> >> y = x.dup may be sufficient for you (it does a shallowcopy). > > Thanks, it worked. Now, what are the differences between object#dup > and object#clone. Both doing shallow copy. It's in the docs: ri Object#clone Object#dup irb(main):001:0> s = "foo".freeze => "foo" irb(main):002:0> t = s.clone => "foo" irb(main):003:0> t << "ha!" RuntimeError: can't modify frozen string from (irb):3 from /opt/bin/irb19:12:in `
' irb(main):004:0> t = s.dup => "foo" irb(main):005:0> t << "ho!" => "fooho!" irb(main):006:0> t => "fooho!" Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/