红宝石 |哈希值函数
Hash#values()是一个 Hash 类方法,它返回散列中存在的值。
Syntax: Hash.values()
Parameter: Hash values
Return: hash values
示例 #1:
# Ruby code for Hash.values() method
# declaring Hash value
a = {a:100, b:200}
# declaring Hash value
b = {a:100, c:300, b:200}
# declaring Hash value
c = {a:100}
# values Value
puts "Hash a values form : #{a.values()}\n\n"
puts "Hash b values form : #{b.values()}\n\n"
puts "Hash c values form : #{c.values()}\n\n"
输出 :
Hash a values form : [100, 200]
Hash b values form : [100, 300, 200]
Hash c values form : [100]
示例 #2:
# Ruby code for Hash.values() method
# declaring Hash value
a = { "a" => 100, "b" => 200 }
# declaring Hash value
b = {"a" => 100}
# declaring Hash value
c = {"a" => 100, "c" => 300, "b" => 200}
# values Value
puts "Hash a values form : #{a.values()}\n\n"
puts "Hash b values form : #{b.values()}\n\n"
puts "Hash c values form : #{c.values()}\n\n"
输出 :
Hash a values form : [100, 200]
Hash b values form : [100]
Hash c values form : [100, 300, 200]