From: Shawn W_ Date: 2010-07-21T14:00:52+09:00 Subject: Re: Return nothing when looking outside the bounds of 2D array? Shawn W_ wrote: > Dave Howell wrote: >> OK, let's try this from the top. {grin} Here's some fresh new code: > > What my program does is generate an array, then populates each cell of > that array with a hash. It looks like when it tries to access the hash > values outside the array boundary it runs into problems? Do I need > another method inside the Array2D class to deal with hash access? If so, > how can this be done? If not, can anyone see any other reason for the > error? I think I got it. I did away with storing my cell data in a hash; rather I will put an array in each cell of the 2D array, and add another parameter to the def [] and def []= methods to access it. So: new_2Darray = Array2D(10,5) new_2Darray[3,1,4,0] = "H" printing out the array gives: X X X X X X X X X X X X X H X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X column = 3 row = 1 cell index = 4 (5th element of the array sitting in that cell of the 2D array) direction = 0 I'm not sure how efficient this will be, or whether it will be restrictive in using some of the default Ruby methods, but it's certainly makes my code very neat. Thx again for everyone's help. -- Posted via http://www.ruby-forum.com/.