O to_matrix() é um método embutido em Ruby que retorna uma array que é apenas self.

Sintaxe : mat1.to_matrix()

Parâmetros : A função precisa da array que deve ser retornada.

Valor de retorno : ele retorna uma array ou self.

Exemplo 1 :

# Ruby program for to_matrix() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[3, 12], [2, 8]]  
   
# Prints the to_matrix matrix
puts  mat1.to_matrix()

Produto :

Matrix[[3, 12], [2, 8]]

Exemplo 2 :

# Ruby program for to_matrix() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[1, 0], [6, 1], [1, 2]]  
   
# Prints the to_matrix matrix
puts  mat1.to_matrix()

Produto :

Matrix[[1, 0], [6, 1], [1, 2]]