Class: Vida::Cell

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cell

Returns a new instance of Cell.



4
5
6
7
8
# File 'lib/vida/cell.rb', line 4

def initialize(args)
  @alive  = args.fetch(:alive)
  @x      = args.fetch(:x)
  @y      = args.fetch(:y)
end

Instance Attribute Details

#aliveObject (readonly)

Returns the value of attribute alive.



2
3
4
# File 'lib/vida/cell.rb', line 2

def alive
  @alive
end

#xObject (readonly)

Returns the value of attribute x.



2
3
4
# File 'lib/vida/cell.rb', line 2

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



2
3
4
# File 'lib/vida/cell.rb', line 2

def y
  @y
end

Instance Method Details

#to_sObject



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

def to_s
  alive ? 'o' : ' '
end

#update_status(live_cells_around) ⇒ Object



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

def update_status(live_cells_around)
  @alive = alive ? (2..3) === live_cells_around : 3 == live_cells_around
end