Sha256: cbe770c3305b532dc6a472730c52b24adfc59fb56eaeac7dd158a2200b2314ec

Contents?: true

Size: 788 Bytes

Versions: 55

Compression:

Stored size: 788 Bytes

Contents

class Grid
  
  attr_accessor :contents
  
  def initialize(rows, cols)
    @contents = []
    rows.times do @contents << [0] * cols end
  end
  
  def rows
    @contents.size
  end
  
  def columns
    @contents[0].size
  end
  
  def ==(other)
    self.contents == other.contents
  end
  
  def create_at(row,col)
    @contents[row][col] = 1
  end
  
  def destroy_at(row,col)
    @contents[row][col] = 0
  end
  
  def self.from_string(str)
    row_strings = str.split(' ')
    grid = new(row_strings.size, row_strings[0].size)
    
    row_strings.each_with_index do |row, row_index|
      row_chars = row.split(//)
      row_chars.each_with_index do |col_char, col_index|
        grid.create_at(row_index, col_index) if col_char == 'X'
      end
    end
    return grid
  end
  
end

Version data entries

55 entries across 55 versions & 10 rubygems

Version Path
dchelimsky-rspec-1.1.10 examples/stories/game-of-life/life/grid.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/game-of-life/life/grid.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/game-of-life/life/grid.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/game-of-life/life/grid.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/game-of-life/life/grid.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/game-of-life/life/grid.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/game-of-life/life/grid.rb
deckshuffler-0.0.2 vendor/plugins/rspec/examples/story/game-of-life/life/grid.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb
picolena-0.1.0 rails_plugins/rspec/examples/stories/game-of-life/life/grid.rb
picolena-0.1.1 rails_plugins/rspec/examples/stories/game-of-life/life/grid.rb
picolena-0.1.3 rails_plugins/rspec/examples/stories/game-of-life/life/grid.rb
picolena-0.1.4 rails_plugins/rspec/examples/stories/game-of-life/life/grid.rb
picolena-0.1.2 rails_plugins/rspec/examples/stories/game-of-life/life/grid.rb
picolena-0.1.5 rails_plugins/rspec/examples/stories/game-of-life/life/grid.rb
pictrails-0.5.0 vendor/plugins/rspec/examples/stories/game-of-life/life/grid.rb