From: Derrick Fiedler Date: 2009-11-15T03:21:41+09:00 Subject: Re: how to copy array in ruby you can make it via this method "clone" b = a.clone Am 14.11.2009 um 11:25 schrieb PIKI: > On Nov 13, 6:34 pm, Jesús Gabriel y Galán > wrote: >> On Fri, Nov 13, 2009 at 2:30 PM, PIKI wrote: >>> But I am struggling tocopyanarray. >> >>> I am using >> >>> a = [] >>> b = a >> >>> /* some manipulation here on "b" and "a" I havent touched at all*/ >> >>> Here when i am trying to see contents of "a" and "b" both have same >>> contents >> >>> But my expectation was they shud be different >> >>> Instead of b = a, I also tried b.replace(a) >> >>> but no luck here also. >> >>> Please help me on how to make a duplicate("b") of "a" so that >>> changes >>> done on b will not affect a >> >> irb(main):001:0> a = [1,2,3,4] >> => [1, 2, 3, 4] >> irb(main):002:0> b = a.dup >> => [1, 2, 3, 4] >> irb(main):003:0> b[0] = 55 >> => 55 >> irb(main):004:0> a >> => [1, 2, 3, 4] >> irb(main):005:0> b >> => [55, 2, 3, 4] >> >> Hope this helps, >> >> Jesus.- Hide quoted text - >> >> - Show quoted text - > > Hi Jesús Gabriel y Galán > > Thanks for the reply and help > > I tried ur solution but it is also not working :( > > I am unable to figure out the trick > > Thanks > Pikender Sharma >