Newbie: Case statement

Graham,

As a newbie I'm confused about the Case construct. All
the documentation I've found states "case operates by
comparing the target with EACH of the expressions after
the When keyword"

    The documentation should continue with "performing (expression ===
target), until the comparison returns true"

So my underlying question is:- what's the fastest Ruby
for checking which of the 8 possible adjacent cells on
a board (2D array) are still "on the board"

    This is a very ambiguous question, but I think the answer to "what's
the fastest" is going to be testing each of the eight cells
individually. For example:

cells_left = [
  cell[x - 1][y - 1],
  cell[x ][y - 1],
  cell[x + 1][y - 1],
  cell[x - 1][y ],
  cell[x + 1][y ],
  cell[x - 1][y + ],
  cell[x ][y + 1],
  cell[x + 1][y + 1],
].compact

    I hope this helps.

    - Warren Brown

I think that this is dangerous if x or y are equal to 0. In this case
cell[0 - 1][y - 1] returns cell[width - 1][y - 1] and not nil.

regards,

Brian

···

On Thu, 23 Sep 2004 08:01:00 +0900, Warren Brown wrote:

Graham,

[Snipped Case Statement explication]

    This is a very ambiguous question, but I think the answer to "what's
the fastest" is going to be testing each of the eight cells individually.
For example:

cells_left = [
  cell[x - 1][y - 1],
  cell[x ][y - 1],
  cell[x + 1][y - 1],
  cell[x - 1][y ],
  cell[x + 1][y ],
  cell[x - 1][y + ],
  cell[x ][y + 1],
  cell[x + 1][y + 1],
].compact

    I hope this helps.

    - Warren Brown

--
Brian Schröder
http://www.brian-schroeder.de/