Method: LifeCalculator#num_living_neighbors
- Defined in:
- lib/life_game_viewer/model/life_calculator.rb
#num_living_neighbors(model, row, col) ⇒ Object
Returns an array of [row, col] tuples corresponding to those neighbor cells that are alive.
78 79 80 81 82 83 84 |
# File 'lib/life_game_viewer/model/life_calculator.rb', line 78 def num_living_neighbors(model, row, col) neighbors(model, row, col).inject(0) do |num_living, neighbor| neighbor_row, neighbor_column = neighbor num_living += 1 if model.alive?(neighbor_row, neighbor_column) num_living end end |