Class: BrowserConwayGameOfLife::Universe
- Inherits:
-
Object
- Object
- BrowserConwayGameOfLife::Universe
- Defined in:
- lib/browser_conway_game_of_life/universe.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(rows, cols) ⇒ Universe
constructor
A new instance of Universe.
- #next ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(rows, cols) ⇒ Universe
Returns a new instance of Universe.
5 6 7 8 9 |
# File 'lib/browser_conway_game_of_life/universe.rb', line 5 def initialize(rows, cols) srand 42 @field = Array.new(rows) { Array.new(cols) { Cell.new } } @temp_field = @field.clone end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
3 4 5 |
# File 'lib/browser_conway_game_of_life/universe.rb', line 3 def cols @cols end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
3 4 5 |
# File 'lib/browser_conway_game_of_life/universe.rb', line 3 def rows @rows end |
Instance Method Details
#next ⇒ Object
11 12 13 14 |
# File 'lib/browser_conway_game_of_life/universe.rb', line 11 def next step @temp_field = @field.clone end |
#to_s ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/browser_conway_game_of_life/universe.rb', line 16 def to_s string = '' @field.each do |vector| vector.each do |el| string << el.to_s end string << "\n" end string end |