Ruby Hash values()函数
Hash#values()是一个Hash类方法,用于返回散列中存在的值。
语法。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]