Skip to content
Related Articles

Related Articles

Ruby | Hash value? method
  • Last Updated : 07 Jan, 2020

Hash#value?() is a Hash class method which checks whether the argumented ‘value’ is presaent in the array or not.

Syntax: Hash.value?()

Parameter: Hash value?

Return: true – if argumented ‘value’ is presaent in the array otherwise return false

Example #1 :






# 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 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :