Open In App

Ruby | Matrix to_s() function

Last Updated : 07 Jan, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
The to_s() is an inbuilt method in Ruby returns a string containing the matrix as the object.
Syntax: mat1.to_s() Parameters: The function needs the matrix whose string object is to be returned. Return Value: It returns a string or self.
Example 1: Ruby
# 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()
Output:
Matrix[[3, 12], [2, 8]]
Example 2: Ruby
# 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()
Output:
Matrix[[1, 0], [6, 1], [1, 2]]

Next Article

Similar Reads