On Nov 13, 6:34 ¨Âí¬ Ê夨ı¨Â ÇáâòéåÇá¤ÂáÏ <jgabrielyga... / gmail.com>
wrote:
> On Fri, Nov 13, 2009 at 2:30 PM, PIKI <avid.p... / gmail.com> 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ù¸ Gabriel y GaláÏ

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