Class: Cell

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

Overview

Population

Constant Summary collapse

DEAD =
' '
ALIVE =
''

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, *coordinates) ⇒ Cell

Returns a new instance of Cell.



9
10
11
12
13
# File 'lib/cell.rb', line 9

def initialize(state, *coordinates)
  @coordinates = coordinates
  @state = state
  n_indices
end

Instance Attribute Details

#coordinatesObject (readonly)

Returns the value of attribute coordinates.



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

def coordinates
  @coordinates
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/cell.rb', line 23

def alive?
  @state == ALIVE
end

#dead?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/cell.rb', line 19

def dead?
  @state == DEAD
end

#n_indicesObject



15
16
17
# File 'lib/cell.rb', line 15

def n_indices
  @n_indices ||= neighbor_indices
end

#next_gen_fate(live_ncells) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/cell.rb', line 27

def next_gen_fate(live_ncells)
  if @state == ALIVE
    (2..3).cover?(live_ncells) ? ALIVE : DEAD
  elsif @state == DEAD
    live_ncells == 3 ? ALIVE : DEAD
  end
end