Ruby | Matrix to_s() function
Last Updated :
07 Jan, 2020
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:
require "matrix"
mat1 = Matrix[[ 3 , 12 ], [ 2 , 8 ]]
puts mat1.to_s()
|
Output:
Matrix[[3, 12], [2, 8]]
Example 2:
require "matrix"
mat1 = Matrix[[ 1 , 0 ], [ 6 , 1 ], [ 1 , 2 ]]
puts mat1.to_s()
|
Output:
Matrix[[1, 0], [6, 1], [1, 2]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...