to_s () ist eine eingebaute Methode in Ruby , die einen String zurückgibt, der die Matrix als Objekt enthält.

Syntax : mat1.to_s()

Parameter : Die Funktion benötigt die Matrix, deren String-Objekt zurückgegeben werden soll.

Rückgabewert : Es gibt eine Zeichenfolge oder sich selbst zurück.

Beispiel 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()

Ausgang :

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

Beispiel 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()

Ausgang :

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