Ruby | Hash rehash function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 rebuilds the hash for each key Example #1 : Ruby # Ruby code for Hash.rehash() 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} # rehash Value puts "Hash a rehash form : #{a.rehash("a")}\n\n" puts "Hash b rehash form : #{b.rehash("c")}\n\n" puts "Hash c rehash form : #{c.rehash("a")}\n\n" Output : Hash a rehash form : false Hash b rehash form : false Hash c rehash form : false Example #2 : Ruby # Ruby code for Hash.rehash() 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} # rehash Value puts "Hash a rehash form : #{a.rehash()}\n\n" puts "Hash b rehash form : #{b.rehash()}\n\n" puts "Hash c rehash form : #{c.rehash()}\n\n" Output : Hash a rehash form : {"a"=>100, "b"=>200} Hash b rehash form : {"a"=>100} Hash c rehash form : {"a"=>100, "c"=>300, "b"=>200} Comment More infoAdvertise with us Next Article Ruby | Hash rehash function K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads 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 rassoc() function rassoc() is an Hash class method which searches an element through the Hash value. Syntax: Hash.rassoc() Parameter: Hashs for finding elements. Return: searches an element through the Hash value Example #1: Ruby # Ruby code for rassoc() method # declaring Hash value a = { "a" => "a 1 min read Ruby | Hash merge function Hash#merge() is a Hash class method which combines two hash arrays and their content. Syntax: Hash.merge() Parameter: Hash values Return: combine two hash arrays Example #1 : Ruby # Ruby code for Hash.merge() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, 2 min read Ruby | Hash merge! function Hash#merge!() : merge!() is a Hash class method which can add the content the given hash array to the other. Entries with duplicate keys are overwritten with the values from each other_hash successively if no block is given. Syntax: Hash.merge!() Parameter: Hash values Return: add the content the gi 2 min read Ruby | Range hash() function The hash() is an inbuilt method in Ruby returns a hash-code for the given range. The hash-value will vary for every execution. Syntax: range1.hash() Parameters: The function accepts no parameter. Return Value: It returns a hash-code for the given range. Example 1: Ruby # Ruby program for hash() # me 1 min read Like