Class: CellularAutomata::Cell

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aliveObject (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

#columnObject (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

#rowObject (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

#copyObject



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

Returns:

  • (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_sObject



12
13
14
15
# File 'lib/cellular_automata/cell.rb', line 12

def to_s
  return ' ' if dead?
  '*'
end