class Cell

Population

Constants

ALIVE
DEAD

Attributes

coordinates[R]
state[R]

Public Class Methods

new(state, *coordinates) click to toggle source
# File lib/cell.rb, line 9
def initialize(state, *coordinates)
  @coordinates = coordinates
  @state = state
  n_indices
end

Public Instance Methods

alive?() click to toggle source
# File lib/cell.rb, line 23
def alive?
  @state == ALIVE
end
dead?() click to toggle source
# File lib/cell.rb, line 19
def dead?
  @state == DEAD
end
n_indices() click to toggle source
# File lib/cell.rb, line 15
def n_indices
  @n_indices ||= neighbor_indices
end
next_gen_fate(live_ncells) click to toggle source
# File lib/cell.rb, line 27
def next_gen_fate(live_ncells)
  if @state == ALIVE
    (2..3).cover?(live_ncells) ? ALIVE : DEAD
  elsif @state == DEAD
    live_ncells == 3 ? ALIVE : DEAD
  end
end