Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Matrix square?() function

  • Last Updated : 07 Jan, 2020

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :