Class: GameOfLife
- Inherits:
-
Object
- Object
- GameOfLife
- Defined in:
- lib/ruby-life.rb
Instance Attribute Summary collapse
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#time ⇒ Object
Returns the value of attribute time.
-
#timestep ⇒ Object
Returns the value of attribute timestep.
Instance Method Summary collapse
- #advance ⇒ Object
-
#initialize(grid, initial_time = 0, timestep = 1) ⇒ GameOfLife
constructor
A new instance of GameOfLife.
Constructor Details
#initialize(grid, initial_time = 0, timestep = 1) ⇒ GameOfLife
Returns a new instance of GameOfLife.
134 135 136 137 138 |
# File 'lib/ruby-life.rb', line 134 def initialize(grid, initial_time = 0, timestep = 1) @grid = grid @time = initial_time @timestep = timestep end |
Instance Attribute Details
#grid ⇒ Object
Returns the value of attribute grid.
132 133 134 |
# File 'lib/ruby-life.rb', line 132 def grid @grid end |
#time ⇒ Object
Returns the value of attribute time.
132 133 134 |
# File 'lib/ruby-life.rb', line 132 def time @time end |
#timestep ⇒ Object
Returns the value of attribute timestep.
132 133 134 |
# File 'lib/ruby-life.rb', line 132 def timestep @timestep end |
Instance Method Details
#advance ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/ruby-life.rb', line 140 def advance puts "Time: #{time}", "-" * 10 self.time += timestep grid.display grid.next timestep end |