O to_s() é um método embutido em Ruby que retorna uma string contendo a array como o objeto.

Sintaxe : mat1.to_s()

Parâmetros : A função precisa da array cujo objeto string deve ser retornado.

Valor de retorno : ele retorna uma string ou self.

Exemplo 1 :

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

Produto :

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

Exemplo 2 :

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

Produto :

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