Class: Conwy::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/conwy/cell.rb

Instance Method Summary collapse

Constructor Details

#initialize(alive:) ⇒ Cell

Returns a new instance of Cell.



3
4
5
# File 'lib/conwy/cell.rb', line 3

def initialize(alive:)
  @alive = alive
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/conwy/cell.rb', line 7

def alive?
  @alive
end

#next(alive_neighbors:) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/conwy/cell.rb', line 11

def next(alive_neighbors:)
  if alive_neighbors == 3 || (alive? && alive_neighbors == 2)
    self.class.new(alive: true)
  else
    self.class.new(alive: false)
  end
end