红宝石 |哈希值?方法
Hash#value?()是一个 Hash 类方法,它检查参数的“值”是否存在于数组中。
Syntax: Hash.value?()
Parameter: Hash value?
Return: true – if argumented ‘value’ is present in the array otherwise return false
示例 #1:
Ruby
# Ruby code for Hash.value?() 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}
# value? Value
puts "Hash a value? form : #{a.value?(200)}\n\n"
puts "Hash b value? form : #{b.value?(100)}\n\n"
puts "Hash c value? form : #{c.value?(300)}\n\n"
Ruby
# Ruby code for Hash.value?() 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}
# value? Value
puts "Hash a value? form : #{a.value?(200)}\n\n"
puts "Hash b value? form : #{b.value?(200)}\n\n"
puts "Hash c value? form : #{c.value?(300)}\n\n"
输出 :
Hash a value? form : true
Hash b value? form : true
Hash c value? form : false
示例 #2:
红宝石
# Ruby code for Hash.value?() 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}
# value? Value
puts "Hash a value? form : #{a.value?(200)}\n\n"
puts "Hash b value? form : #{b.value?(200)}\n\n"
puts "Hash c value? form : #{c.value?(300)}\n\n"
输出 :
Hash a value? form : true
Hash b value? form : false
Hash c value? form : true