Ruby | Matrix to_a() function Last Updated : 07 Jan, 2020 Improve Improve Like Article Like Save Share Report The to_a() is an inbuilt method in Ruby returns an array which has all the elements of the matrix row-wise. Syntax: mat1.to_a() Parameters: The function needs the matrix which is to be converted to an array. Return Value: It returns an array. Example 1: # Ruby program for to_a() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[3, 12], [2, 8]] # Prints the to_a matrix puts mat1.to_a() Output: 3 12 2 8 Example 2: # Ruby program for to_a() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 0], [6, 1], [1, 2]] # converted to array arr = mat1.to_a() # Prints the array puts arr Output: 1 0 6 1 1 2 Like Article Suggest improvement Previous Ruby | Matrix identity() function Next Ruby | Hash each() function Share your thoughts in the comments Add Your Comment Please Login to comment...