From: Pieter Mans Date: 2007-07-12T06:51:18+09:00 Subject: Re: Accessing a specific index in a nested array Florian Gross wrote: >> For example, this works: >> irb> array[2] >> => [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] >> >> But this doesn't seem to: >> irb> array[2[2]] >> => [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] >> >> I'm pretty sure I'm just getting the syntax wrong. > > Yup, you're calling [] on the number 2. You want array[2][2]. Thanks! That worked nicely. I'm getting a weird problem when setting values tho. When I try to set the value of an item in a nested array, it sets the value in all the other nested arrays too: irb> test = Map.new(5,5) => # irb> test.coords[1][1] = 0 => 0 irb> test.coords => [["#", 0, "#", "#", "#"], ["#", 0, "#", "#", "#"], ["#", 0, "#", "#", "#"], ["#", 0, "#", "#", "#"], ["#", 0, "#", "#", "#"]] Any idea what I'm doing wrong? -- Posted via http://www.ruby-forum.com/.