Ruby | Matrix zero?() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The zero?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a zero matrix, else it returns false. Zero matrix means that the matrix has all itselements as 0.Syntax: mat1.zero?()Parameters: The function needs the matrix to be checked for zero matrix.Return Value: It returns true if it is a zero matrix, else it returns false.Example 1: Ruby # Ruby program for zero?() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[1, 21], [31, 18]] # Prints if zero matrix or not puts mat1.zero?() Output: falseExample 2: Ruby # Ruby program for zero?() method in Matrix # Include matrix require "matrix" # Initialize a matrix mat1 = Matrix[[0, 0, 0], [0, 0, 0], [0, 0, 0]] # Prints if zero or not puts mat1.zero?() Output: true Comment More infoAdvertise with us Next Article Ruby | Matrix zero() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Matrix-class Similar Reads Ruby | Matrix zero() function The zero() is an inbuilt method in Ruby returns an N x M zero matrix where each element is zero. Syntax: mat1.zero(N, M) Parameters: The function accepts two mandatory parameters N and M which is the size of the matrix. Return Value: It returns the zero matrix of size N x M. Example 1: Ruby # Ruby p 1 min read Ruby | Matrix zero() function The zero() is an inbuilt method in Ruby returns an N x M zero matrix where each element is zero. Syntax: mat1.zero(N, M) Parameters: The function accepts two mandatory parameters N and M which is the size of the matrix. Return Value: It returns the zero matrix of size N x M. Example 1: Ruby # Ruby p 1 min read Ruby | Matrix to_a() function 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 # Ruby program for to_a() method in Matri 1 min read Ruby | Matrix to_a() function 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 # Ruby program for to_a() method in Matri 1 min read Ruby | Numeric zero? function The zero?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a negative one, else it returns false. Syntax: num.zero?() Parameters: The function needs a number which is to be checked for. Return Value: It returns returns a boolean value. Example 1: CPP # Ruby pr 1 min read Ruby | Numeric zero? function The zero?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is a negative one, else it returns false. Syntax: num.zero?() Parameters: The function needs a number which is to be checked for. Return Value: It returns returns a boolean value. Example 1: CPP # Ruby pr 1 min read Like