Open In App

Ruby | Matrix to_matrix() function

Last Updated : 12 Jul, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The to_matrix() is an inbuilt method in Ruby returns a matrix which is self only.
Syntax: mat1.to_matrix() Parameters: The function needs the matrix which is to be returned. Return Value: It returns an matrix, or self.
Example 1: Ruby
# 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()
Output:
Matrix[[3, 12], [2, 8]]
Example 2: Ruby
# 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()
Output:
Matrix[[1, 0], [6, 1], [1, 2]]

Similar Reads