Hi,

If you write matriz[0][0], you will get the array

[ [“Armando”, “P”], [“Dave”, “S”] ]

That’s because matriz[0] yields the first entry of matriz, which is

[

[ [“Armando”, “P”], [“Dave”, “S”] ],

[ [“Richard”, “R”], [“Michael”, “S”] ],

]

And matriz[0][0] yields the first entry of this array, which is

[ [“Armando”, “P”], [“Dave”, “S”] ]

I’m not sure if that is what you wanted? If you want the matrix to

consist of name entries like [“Armando”, “P”], you will have to change

its structure. This code, for example, generates a matrix with 4 rows

and 2 columns:

my_matrix = [

# row 0

[

# column 0

[“Armando”, “P”],

# column 1

[“Dave”, “S”]

],

# row 1

[

# column 0

[“Richard”, “R”],

# column 1

[“Michael”, “S”]

],

# row 2

[

# column 0

[“Allen”, “S”],

# column 1

[“Omer”, “P”]

],

# row 3

[

# column 0

[“David E.”, “R”],

# column 1

[“Richard X.”, “P”]

]

]

By my_matrix[0][0] you will now get the name array

[“Armando”, “P”]

You can check this by writing

p my_matrix[0][0]

Don’t use the “puts” method in this case. It will print out every entry

of the array line by line instead of showing the array itself.

To iterate over every matrix element, you can write

my_matrix.each do |row|

row.each do |entry|

p entry

end

end

my_matrix.each iterates over the entries of my_matrix, which are the

rows of the matrix. And then you iterate over the entries of the rows,

which are the elements of the matrix.

By the way: Ruby has a built-in class for matrices. That’s probably what

you are looking for.

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/matrix/rdoc/

Jacques