Ruby | Hash has_value?() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Hash#has_value?() is a Hash class method which checks whether the given value is present in hash. Syntax: Hash.has_value?() Parameter: Hash values Return: true - if given value is present in hash otherwise return false Example #1 : Ruby # Ruby code for Hash.has_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} # has_value? Value puts "Hash a has_value? form : #{a.has_value?(200)}\n\n" puts "Hash b has_value? form : #{b.has_value?(10)}\n\n" puts "Hash c has_value? form : #{c.has_value?(100)}\n\n" Output : Hash a has_value? form : true Hash b has_value? form : false Hash c has_value? form : true Example #2 : Ruby # Ruby code for Hash.has_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} # has_value? Value puts "Hash a has_value? form : #{a.has_value?(200)}\n\n" puts "Hash b has_value? form : #{b.has_value?(10)}\n\n" puts "Hash c has_value? form : #{c.has_value?(100)}\n\n" Output : Hash a has_value? form : true Hash b has_value? form : false Hash c has_value? form : true 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 values function Hash#values() is a Hash class method which returns the values present in the hash. Syntax: Hash.values() Parameter: Hash values Return: hash values Example #1 : Ruby # Ruby code for Hash.values() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # decl 1 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 has_key?() function 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} 2 min read Ruby | Hash fetch_values() function Hash#fetch_values() is a Hash class method which returns array containing the values associated with the given keys. With no other arguments, it will raise a KeyError exception. Syntax: Hash.fetch_values() Parameter: Hash values Return: array containing the values associated with the given keys Exam 1 min read Ruby | Vector hash() function The hash() is an inbuilt method in Ruby returns hash code of the vector Syntax: vec1.hash() Parameters: The function accepts no parameter. Return Value: It returns hash code of the vector. Example 1: Ruby # Ruby program for hash() method in Vector # Include matrix require "matrix" # Initia 1 min read Ruby | Vector hash() function The hash() is an inbuilt method in Ruby returns hash code of the vector Syntax: vec1.hash() Parameters: The function accepts no parameter. Return Value: It returns hash code of the vector. Example 1: Ruby # Ruby program for hash() method in Vector # Include matrix require "matrix" # Initia 1 min read Like