Class: GameOfLife::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/game-of-life/cell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = 0, y = 0, alive = true) ⇒ Cell

Returns a new instance of Cell.



4
5
6
7
# File 'lib/game-of-life/cell.rb', line 4

def initialize(x=0,y=0,alive=true)
  @x,@y = x,y
  @alive = alive
end

Instance Attribute Details

#aliveObject

Returns the value of attribute alive.



3
4
5
# File 'lib/game-of-life/cell.rb', line 3

def alive
  @alive
end

#neighboursObject

Returns the value of attribute neighbours.



3
4
5
# File 'lib/game-of-life/cell.rb', line 3

def neighbours
  @neighbours
end

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/game-of-life/cell.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/game-of-life/cell.rb', line 3

def y
  @y
end

Instance Method Details

#==(otherCell) ⇒ Object



9
10
11
# File 'lib/game-of-life/cell.rb', line 9

def ==(otherCell)
  (self.x == otherCell.x) and (self.y == otherCell.y)
end

#alive?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/game-of-life/cell.rb', line 17

def alive?
  self.alive
end

#dead?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/game-of-life/cell.rb', line 21

def dead?
  not alive?
end

#die!Object



29
30
31
# File 'lib/game-of-life/cell.rb', line 29

def die!
  @alive = false
end

#reborn!Object



25
26
27
# File 'lib/game-of-life/cell.rb', line 25

def reborn!
  @alive = true
end