From: Robert Klemme Date: 2003-12-01T17:12:11+09:00 Subject: Re: New to ruby--trouble with initializing arrays "Van Jacques" schrieb im Newsbeitrag news:70ae81fd.0311281947.909cec1@posting.google.com... > I am writing a practice program; the Game of Life. Naturally I am having troubles. > > This will probably be elementary those with experience in programming with ruby, > so please tell me the right place to post such questions if this is not the place. > > The program is not running as I think it should. > > I think it may be due to the way I set up the arrays, so that many elements refer to > the same element, and then later in the program when they should be different > they remain the same. Does this help: class Board def initialize(size=8) @size = 8 @values = Array.new( size * size, 0 ) end def [](x,y) @values[x*@size+y] end def []=(x,y,v) @values[x*@size+y]=v end end board = Board.new tmp = board.dup # manipulate tmp board = tmp If you store something other than integers in the cells you could add this method: dup copy = super copy.instance_eval {@values.map! {|v| v.dup } } copy end Cheers robert