Class: CellularAutomata::Cell
- Inherits:
-
Object
- Object
- CellularAutomata::Cell
- Defined in:
- lib/cellular_automata/cell.rb
Instance Attribute Summary collapse
-
#alive ⇒ Object
(also: #alive?)
readonly
Returns the value of attribute alive.
-
#column ⇒ Object
(also: #x)
readonly
Returns the value of attribute column.
-
#row ⇒ Object
(also: #y)
readonly
Returns the value of attribute row.
Instance Method Summary collapse
- #copy ⇒ Object
- #dead? ⇒ Boolean
- #die! ⇒ Object
-
#initialize(alive: false, row:, column:) ⇒ Cell
constructor
A new instance of Cell.
- #live! ⇒ Object
- #survive! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(alive: false, row:, column:) ⇒ Cell
Returns a new instance of Cell.
6 7 8 9 10 |
# File 'lib/cellular_automata/cell.rb', line 6 def initialize(alive: false, row: , column:) @alive = alive @row = row @column = column end |
Instance Attribute Details
#alive ⇒ Object (readonly) Also known as: alive?
Returns the value of attribute alive.
2 3 4 |
# File 'lib/cellular_automata/cell.rb', line 2 def alive @alive end |
#column ⇒ Object (readonly) Also known as: x
Returns the value of attribute column.
2 3 4 |
# File 'lib/cellular_automata/cell.rb', line 2 def column @column end |
#row ⇒ Object (readonly) Also known as: y
Returns the value of attribute row.
2 3 4 |
# File 'lib/cellular_automata/cell.rb', line 2 def row @row end |
Instance Method Details
#copy ⇒ Object
32 33 34 |
# File 'lib/cellular_automata/cell.rb', line 32 def copy self.class.new(alive: alive?, row: row, column: column) end |
#dead? ⇒ Boolean
28 29 30 |
# File 'lib/cellular_automata/cell.rb', line 28 def dead? !alive? end |
#die! ⇒ Object
21 22 23 |
# File 'lib/cellular_automata/cell.rb', line 21 def die! @alive = false end |
#live! ⇒ Object
17 18 19 |
# File 'lib/cellular_automata/cell.rb', line 17 def live! @alive = true end |
#survive! ⇒ Object
25 26 |
# File 'lib/cellular_automata/cell.rb', line 25 def survive! end |
#to_s ⇒ Object
12 13 14 15 |
# File 'lib/cellular_automata/cell.rb', line 12 def to_s return ' ' if dead? '*' end |