红宝石 |矩阵 hash()函数
hash()是 Ruby 中的一个内置方法,它返回矩阵的哈希码。
Syntax: mat1.hash()
Parameters: The function does not accepts any parameter.
Return Value: It returns the hash-code of the matrix.
示例 1 :
Ruby
# Ruby program for hash() method in Matrix
# Include matrix
require "matrix"
# Initializes the matrix
mat1 = Matrix[[12, 21], [31, 12]]
# Prints the hash-code
puts mat1.hash()
Ruby
# Ruby program for hash() method in Matrix
# Include matrix
require "matrix"
# Initializes the matrix
mat1 = Matrix[[6, 7], [9, 10], [12, 4]]
# Prints the hash-code
puts mat1.hash()
输出:
631900695216402634
示例 2 :
红宝石
# Ruby program for hash() method in Matrix
# Include matrix
require "matrix"
# Initializes the matrix
mat1 = Matrix[[6, 7], [9, 10], [12, 4]]
# Prints the hash-code
puts mat1.hash()
输出:
-1308023948917233670]