class GameOfLife::Cell
Represents a single cell in a Game of Life
Attributes
state[RW]
Public Class Methods
new(state = :dead)
click to toggle source
# File lib/game_of_life/cell.rb, line 8 def initialize(state = :dead) @state = state end
Public Instance Methods
to_s()
click to toggle source
# File lib/game_of_life/cell.rb, line 25 def to_s case @state when :live "#" when :dead "." end end
update_state(neighbors)
click to toggle source
# File lib/game_of_life/cell.rb, line 12 def update_state(neighbors) live_neighbors = neighbors.select { |cell| cell.state == :live } case live_neighbors.size when 0..1 @state = :dead when 3 @state = :live when 4..8 @state = :dead end self end