Class: Vida::Cell
- Inherits:
-
Object
- Object
- Vida::Cell
- Defined in:
- lib/vida/cell.rb
Instance Attribute Summary collapse
-
#alive ⇒ Object
readonly
Returns the value of attribute alive.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(args) ⇒ Cell
constructor
A new instance of Cell.
- #to_s ⇒ Object
- #update_status(live_cells_around) ⇒ Object
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
#alive ⇒ Object (readonly)
Returns the value of attribute alive.
2 3 4 |
# File 'lib/vida/cell.rb', line 2 def alive @alive end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
2 3 4 |
# File 'lib/vida/cell.rb', line 2 def x @x end |
#y ⇒ Object (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_s ⇒ Object
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 |