Implementing the Grid Class

Learn how to create grids in Ruby.

We'll cover the following

Implementing the Grid class

As seen in the previous lesson, the Grid class is essentially just a wrapper around a two-dimensional array of cells. Let’s add the following code into a file named grid.rb, making sure it’s in the same directory as the cell.rb file we created earlier so the grid can find the Cell class that it needs. Let's walk through this together, one piece at a time.

First, we require the Cell class that we just wrote since the grid depends on it. Note also that the grid keeps track of the number of rows and columns it comprises.

grid.rb

Get hands-on with 1200+ tech skills courses.