红宝石 |矩阵 eql?函数
情商?是 Ruby 中的一个内置方法,返回一个布尔值。如果两个矩阵相等,则返回 true,否则返回 false。
Syntax: mat1.eql?(mat2)
Parameters: The function need two matrix mat1 and mat2 which are to be compared.
Return Value: It returns true if both the matrix are equal or else it returns false.
示例 1 :
Ruby
# Ruby program for eql? method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
mat2 = Matrix[[1, 21], [31, 18]]
# Prints if both are equal or not
puts mat1.eql?(mat2)
Ruby
# Ruby program for eql? method in Matrix
# Include matrix
require "matrix"
# Initializes the matrix
mat1 = Matrix[[1, 21], [31, 18]]
mat2 = Matrix[[1, 16], [31, 28]]
# Prints if both are equal or not
puts mat1.eql?(mat2)
输出:
true
示例 2 :
红宝石
# Ruby program for eql? method in Matrix
# Include matrix
require "matrix"
# Initializes the matrix
mat1 = Matrix[[1, 21], [31, 18]]
mat2 = Matrix[[1, 16], [31, 28]]
# Prints if both are equal or not
puts mat1.eql?(mat2)
输出:
false