Class: Conwy::Cell
- Inherits:
-
Object
- Object
- Conwy::Cell
- Defined in:
- lib/conwy/cell.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(alive:) ⇒ Cell
constructor
A new instance of Cell.
- #next(alive_neighbors:) ⇒ Object
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
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 |