Ruby | Hash include?() function
Hash#include?() is a Hash class method which checks whether the given key is present in hash.
Syntax: Hash.include?()
Parameter: Hash values
Return: true – if given key”” is present in hash otherwise return false
Example #1 :
# Ruby code for Hash.has_value?() method # declaring Hash valuea = {a:100, b:200} # declaring Hash valueb = {a:100, c:300, b:200} # declaring Hash valuec = {a:100} # has_value? Valueputs "Hash a has_value? form : #{a.include?("a")}\n\n" puts "Hash b has_value? form : #{b.has_value?("c")}\n\n" puts "Hash c has_value? form : #{c.has_value?("c")}\n\n" |
Output :
Hash a has_value? form : false Hash b has_value? form : false Hash c has_value? form : false
Example #2 :
# Ruby code for Hash.has_value?() method # declaring Hash valuea = { "a" => 100, "b" => 200 } # declaring Hash valueb = {"a" => 100} # declaring Hash valuec = {"a" => 100, "c" => 300, "b" => 200} # has_value? Valueputs "Hash a has_value? form : #{a.include?("a")}\n\n" puts "Hash b has_value? form : #{b.has_value?("c")}\n\n" puts "Hash c has_value? form : #{c.has_value?("c")}\n\n" |
Output :
Hash a has_value? form : true Hash b has_value? form : false Hash c has_value? form : false


