From: John W Higgins Date: 2009-07-08T03:12:16+09:00 Subject: Re: Manipulating Multi-Dimensional Array --0016e64ec390f18529046e218f2e Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Morning Tyler, On Tue, Jul 7, 2009 at 10:51 AM, Tyler Knappe wrote: > I'm attempting to modify elements within a multi-dimensional array. > However, syntax like calendar[0][0] = 'True' results in the entire > calendar[0..6][0] portion of the multi-dimensional array to be set to > 'True'. Can anyone explain to me why this is occurring? > > irb(main):192:0> calendar = [] > => [] > irb(main):193:0> cal = [] > => [] > irb(main):194:0> for i in 0..6 do > irb(main):195:1* for j in 0..23 do > irb(main):196:2* cal[j] = j > irb(main):197:2> calendar[i] = cal You set each member of calendar to the same array. That is why when you change the value of calendar[0][0] you are actually modifying cal[0] which means you are modifying calendar[0][0], calendar[1][0], and so on because calendar[0] == calendar[1] == cal You can try for i = 0..6 do calendar[i] = [] for j = 0..23 do calendar[i][j] = j end end John --0016e64ec390f18529046e218f2e--