3 attr_accessor :contents
5 def initialize(rows, cols)
7 rows.times do @contents << [0] * cols end
19 self.contents == other.contents
22 def create_at(row,col)
23 @contents[row][col] = 1
26 def destroy_at(row,col)
27 @contents[row][col] = 0
30 def self.from_string(str)
31 row_strings = str.split(' ')
32 grid = new(row_strings.size, row_strings[0].size)
34 row_strings.each_with_index do |row, row_index|
35 row_chars = row.split(//)
36 row_chars.each_with_index do |col_char, col_index|
37 grid.create_at(row_index, col_index) if col_char == 'X'