Class: Conway::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/conway/rules.rb,
lib/conway/rules/default.rb,
lib/conway/rules/stability.rb,
lib/conway/rules/live_count.rb,
lib/conway/rules/reproduction.rb,
lib/conway/rules/over_population.rb,
lib/conway/rules/under_population.rb

Defined Under Namespace

Modules: LiveCount Classes: Default, OverPopulation, Reproduction, Stability, UnderPopulation

Instance Method Summary collapse

Constructor Details

#initialize(rules = [UnderPopulation.new, Stability.new, OverPopulation.new, Reproduction.new, Default.new]) ⇒ Rules

Returns a new instance of Rules.



9
10
11
12
13
14
15
# File 'lib/conway/rules.rb', line 9

def initialize(rules=[UnderPopulation.new,
                      Stability.new,
                      OverPopulation.new,
                      Reproduction.new,
                      Default.new])
  self.rules = rules
end

Instance Method Details

#apply(cell, neighbors) ⇒ Object



17
18
19
20
21
22
# File 'lib/conway/rules.rb', line 17

def apply(cell, neighbors)
  rules.map do |rule|
    next_cell = rule.apply(cell, neighbors)
    break next_cell if next_cell
  end
end