Open In App

Ruby | Matrix square?() function

Improve
Improve
Like Article
Like
Save
Share
Report

The square?() is an inbuilt method in Ruby returns a boolean value. It returns true if it is a square matrix, else it returns false.

Syntax: mat1.square?()

Parameters: The function needs the matrix to be checked for square matrix or not.

Return Value: It returns true if it is a square matrix, else it returns false.

Example 1:




# Ruby program for square?() method in Matrix
  
# Include matrix 
require "matrix"
  
# Initialize a matrix 
mat1 = Matrix[[3, 12], [2, 8]]  
  
# Prints if square? or not 
puts  mat1.square?()


Output:

true

Example 2:




# Ruby program for square?() method in Matrix
  
# Include matrix 
require "matrix"
  
# Initialize a matrix 
mat1 = Matrix[[1, 0], [0, 1], [1, 2]]  
  
# Prints if square? or not 
puts  mat1.square?()


Output:

false

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads