Q:

Cannot create Ruby matrix using ::diagonal from array

I am trying to create a matrix in Ruby using the ::diagonal method. A is an array I create. What I want to do is the populate the diagonal of a_new_matrix with every number in A, but instead what I get is a_new_matrix[0,0] is A. How could I solve this?
A = Array.new
... #populate A
a_new_matrix = Matrix.diagonal(A)

A:

What I want to do is the populate the diagonal of a_new_matrix with every number in A

From the docs:
Matrix.diagonal(9, 5, -3)
#=>  9  0  0
#    0  5  0
#    0  0 -3

So, for an array you can use the splat operator (*):
ary = [1, 2, 3]
Matrix.diagonal(*ary)
#=> Matrix[[1, 0, 0], [0, 2, 0], [0, 0, 3]]

A is an array I create

Careful, uppercase identifiers are constants.  A is a constant, a is a variable.

