From: Robert Klemme Date: 2003-12-01T22:37:07+09:00 Subject: Re: New to ruby--trouble with initializing arrays "Robert Klemme" schrieb im Newsbeitrag news:bqet0g$21995e$1@ID-52924.news.uni-berlin.de... > > "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: Slightly improved to tackle the borders. class Board def initialize(size=8) @size = 8 @values = Array.new( size * size, 0 ) end def [](x,y) @values[pos(x,y)]=v end def []=(x,y,v) @values[pos(x,y)]=v end protected def pos(x,y) ( x % @size ) * @size + ( y % @size ) end end > board = Board.new > tmp = board.dup > # manipulate tmp > board = tmp robert