O'Reilly logo

Sams Teach Yourself Ruby in 21 Days by Mark Slagell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An IntegerMatrix Class

Throughout this chapter we'll be building an IntegerMatrix class. Our matrices will hold numbers in rectangular grids of arbitrary sizes and allow certain kinds of math to be carried out on them.

It so happens that Ruby already comes with a sophisticated Matrix class. It lives in the matrix.rb module and is found by a script containing the line require 'matrix' or load 'matrix.rb'. Our IntegerMatrix will be much different, and will not pretend to be a functional approximation of Matrix.

Incidentally, there would be no name conflict if we called our class Matrix as well, so long as it was in a file that was not named matrix.rb and it was used only by scripts that didn't use the other kind of matrix.

Initialization

The first ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required