红宝石 |字符串哈希方法
hash是 Ruby 中的 String 类方法,用于根据字符串的长度、内容和编码返回哈希值。
Syntax: str.hash
Parameters: Here, str is the given string.
Returns: A hash based on the string’s length, content and encoding.
示例 1:
# Ruby program to demonstrate
# the hash method
# Taking a string and
# using the method
puts "Ruby".hash
puts "String".hash
输出:
3142682481284465636
-3118341609802567384
示例 2:
# Ruby program to demonstrate
# the hash method
# Taking a string and
# using the method
puts "Sample".hash
puts "Program".hash
输出:
1285954436548758293
-6969951348417810