Class: SlackGame::Game::Lifegame::Cell
- Inherits:
-
Object
- Object
- SlackGame::Game::Lifegame::Cell
- Defined in:
- lib/slack_game/game/lifegame.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(alive) ⇒ Cell
constructor
A new instance of Cell.
- #next_gen(arround_cells) ⇒ Object
Constructor Details
#initialize(alive) ⇒ Cell
Returns a new instance of Cell.
71 72 73 |
# File 'lib/slack_game/game/lifegame.rb', line 71 def initialize(alive) @alive = !! alive end |
Instance Method Details
#alive? ⇒ Boolean
75 76 77 |
# File 'lib/slack_game/game/lifegame.rb', line 75 def alive? !! @alive end |
#next_gen(arround_cells) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/slack_game/game/lifegame.rb', line 79 def next_gen(arround_cells) alives = arround_cells.select(&:alive?).size if alive? (alives <= 1 || 4 <= alives) ? Cell.new(false) : Cell.new(true) else alives == 3 ? Cell.new(true) : Cell.new(false) end end |