Method: Grid#map_a

Defined in:
lib/cem/cruzzles.rb

#map_a(&block) ⇒ Object

Maps each cell of the grid by the given block.

If block has…

- one parameter, passes the cell value
- two parameters, passes y and x
- three parameteres, passes y, x and the cell value


488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/cem/cruzzles.rb', line 488

def map_a(&block)

  case block.arity
    when 1 
      @data.map { |row| row.map { |value| block.call(value) } }
    when 2 
      @data.each_with_index.map { |row, y| row.each_index.map { |x| block.call(y,x) } }
    when 3      
      @data.each_with_index.map { |row, y| row.each_with_index.map { |cell, x| block.call(y,x,cell) } }
    else
      raise
  end

end