From: Gianfranco Bozzetti Date: 2010-08-21T00:31:56+09:00 Subject: Re: Need help with hash.to_s for enumerated items Sem Ptiri wrote: > I have a grid with keys > > grid.keys > => [[1, 2], [0, 0], [3, 3], [2, 1], [1, 1], [0, 3], [3, 2], [2, 0], [1, > 0], [0, 2], [3, 1], [2, 3], [4, 3], [3, 0], [2, 2], [1, 3], [0, 1], [6, > 3]] > > I need to create a list list of all possible combinations. I would start > by taking the first item, then linking it with every other item, then > truncate the first item, and repeat. > > My problem is that on > > grid.keys[0].to_s > => "12" > > it mashes the [1, 2] together making it unusable. On my system array#to_s joins the arrays' elements ("12") arrai#inspect prints the array [1, 2] > Could you suggest a better data structure for storing a list of all > possible combinations? > > Linking a hash [1, 2] to [0, 0] and then [1, 1] would simply override > the previous link. If I understand correctly the problem, you can: 1 - assign the keys to an array varable, say gk=grid.keys 2 - create a list of indexes for each possible pair in gk 3 - access gk via indexes as in: HTH gfb -- Posted via http://www.ruby-forum.com/.