Hash#value?() is a Hash class method which checks whether the argumented ‘value’ is present in the array or not.
Syntax: Hash.value?()
Parameter: Hash value?
Return: true – if argumented ‘value’ is present in the array otherwise return false
Example #1 :
Ruby
a = {a: 100 , b: 200 }
b = {a: 100 , c: 300 , b: 200 }
c = {a: 100 }
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"
|
Output :
Hash a value? form : true
Hash b value? form : true
Hash c value? form : false
Example #2 :
Ruby
a = { "a" => 100 , "b" => 200 }
b = { "a" => 100 }
c = { "a" => 100 , "c" => 300 , "b" => 200 }
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"
|
Output :
Hash a value? form : true
Hash b value? form : false
Hash c value? form : true