From: Frantisek ZACEK Date: 2008-08-18T06:53:05+09:00 Subject: Re: Matrix: Need help to understand this behavior On Sun, Aug 17, 2008 at 4:53 PM, Marcio Braga wrote: > Zacek and all: how to duplicate a matrix that has elements that are also > matrix ? > For example: > > a = [[1]] > b = a.dup > puts a.object_id > puts b.object_id > puts a[0].object_id # the same object > puts b[0].object_id # the same object > b[0][0] = 2 * b[0][0] > p a > p b > > So, matrix "a" and "b" are different objects but each internal matrix > element continue to be the same object. Do I need to duplicate each one > ? > > Thank you > Marcio > -- > Posted via http://www.ruby-forum.com/. > > I don't think there is a simple way to achieve that. I would suggest: a=[[1]] b=a.dup.colllect { |e| e.dup } -- Frantisek ZACEK (zacek_f) -- SRS 2008