Class: Lifelike::Grid
- Inherits:
-
Object
- Object
- Lifelike::Grid
- Defined in:
- lib/lifelike/grid.rb
Defined Under Namespace
Classes: GridSerializer
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rows) ⇒ Grid
constructor
A new instance of Grid.
- #map_with_neighbors ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(rows) ⇒ Grid
Returns a new instance of Grid.
3 4 5 |
# File 'lib/lifelike/grid.rb', line 3 def initialize(rows) @rows = rows end |
Class Method Details
.from_s(string) ⇒ Object
21 22 23 24 25 |
# File 'lib/lifelike/grid.rb', line 21 def self.from_s(string) GridSerializer.load(string) do |char| yield(char) end end |
Instance Method Details
#map_with_neighbors ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/lifelike/grid.rb', line 7 def map_with_neighbors self.class.new( @rows.map.with_index do |row, row_index| row.map.with_index do |cell, col_index| yield(cell, neighbors(row_index, col_index)) end end ) end |
#to_a ⇒ Object
17 18 19 |
# File 'lib/lifelike/grid.rb', line 17 def to_a @rows end |
#to_s ⇒ Object
27 28 29 30 31 |
# File 'lib/lifelike/grid.rb', line 27 def to_s GridSerializer.dump(self) do |cell| yield(cell) end end |