Ruby | Hash value? method
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
# 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" |
Output :
Hash a value? form : true Hash b value? form : true Hash c value? form : false
Example #2 :
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" |
Output :
Hash a value? form : true Hash b value? form : false Hash c value? form : true
Contact Us