From: Tom Willis Date: 2005-03-07T03:55:28+09:00 Subject: Re: Noob:Objects as key in hash On Mon, 7 Mar 2005 03:26:55 +0900, Jim Weirich wrote: > On Sunday 06 March 2005 01:17 pm, ES wrote: > > > Generally speaking, using an object this way might not be the best > > idea. If each Point were an immutable, unique instance (think Fixnum, > > for example), I would think it's OK but I'm somewhat leery of this. >>... Thanks for the replies. The problem I'm trying to solve. Which really isn't a problem, because I'm just experimenting is a board game emulation. I had an idea that a framework could be slapped together for various board games. Tic Tac Toe, Checkers, Chess etc... So to represent the board or get access to the board state, my first stab at it was an immutable collection of coordinates that you can associae arbitrary data with keyed by x,y. I imagine I'd have a board object. And I would access it like this. tictactoe = GameBoard.new(length=3,width=3) tictactoe.place(2,2,"x") tictactoe.place(3,3,"o") tictactoe.place(2,3,"x") tictactoe.place(3,1,"o") tictactoe.place(2,1,"x") >>"x's win" class GamBoard ... def place(x,y,data) @pointcollection[PointID.new(x,y)].data = data if end #previous implementation which I didn't like #because it would be something I'd do in python def place(x,y,data) @pointcollection["#{x}:#{y}"].data = data end ... end haven't figured out the how to determine a winner yet, which is why I didn't start with chess. :) Probably not the best design. But my main goal is learning a new language, and it's more fun than reading a bunch of documentation. :) Probably more than you wanted to know, but this is how I arrived at this little problem /misunderstanding. Thanks again. -- Thomas G. Willis http://paperbackmusic.net