Ruby | Hash has_key?() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Hash#has_key?() is a Hash class method which checks whether the given key is present in hash. Syntax: Hash.has_key?() Parameter: Hash values Return: true - if the key is present otherwise return false Example #1 : Ruby # Ruby code for Hash.has_key?() 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} # has_key? Value puts "Hash a has_key? form : #{a.has_key?("a")}\n\n" puts "Hash b has_key? form : #{b.has_key?("c")}\n\n" puts "Hash c has_key? form : #{c.has_key?("v")}\n\n" Output : Hash a has_key? form : false Hash b has_key? form : false Hash c has_key? form : false Example #2 : Ruby # Ruby code for Hash.has_key?() 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} # has_key? Value puts "Hash a has_key? form : #{a.has_key?("a")}\n\n" puts "Hash b has_key? form : #{b.has_key?("c")}\n\n" puts "Hash c has_key? form : #{c.has_key?("v")}\n\n" Output : Hash a has_key? form : true Hash b has_key? form : false Hash c has_key? form : false Comment More infoAdvertise with us Next Article Ruby | Hash has_key?() function K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash key?() function Hash#key?() is a Hash class method which checks whether the key corresponding to the value is present or not. Syntax: Hash.key?() Parameter: Hash values Return: true - if key corresponding to the value is present otherwise return false Example #1 : Ruby # Ruby code for Hash.key?() method # declaring 2 min read Ruby | Hash key() function Hash#key() is a Hash class method which gives the key value corresponding to the value. If value doesn't exist then return nil. Syntax: Hash.key() Parameter: Hash values Return: key corresponding to the value nil - If value doesn't exist Example #1 : Ruby # Ruby code for Hash.key() method # declarin 2 min read Ruby | Hash keys() function Hash#keys() is a Hash class method which gives an array with all the keys present in the hash. Syntax: Hash.keys() Parameter: Hash values Return: array with all the keys present in the hash Example #1 : Ruby # Ruby code for Hash.keys() method # declaring Hash value a = {a:100, b:200} # declaring Has 2 min read Ruby | Hash rehash function Hash#rehash() : rehash() is a Hash class method which based on the current hash value rebuilds the hash for each key. This will reindex hash if the values of key objects have changed since they were inserted. Syntax: Hash.rehash() Parameter: Hash values Return: based on the current hash value rebuil 2 min read Ruby | Hash each_key function Hash#each_key() is a Hash class method which finds the nested value which calls block once for each_key pair in the hash by passing the key as parameters. Syntax: Hash.each_key() Parameter: Hash values Return: calls block once for key_value pair in hash with key as a parameter otherwise, Enumerator 2 min read Like