Ruby | Hash clear() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report clear() is an Hash class method which removes all the Hash elements from it. Syntax: Hash.clear() Parameter: Hashs to clear off Return: Hash with all elements cleared Example #1: Ruby # Ruby code for clear() 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} puts "clear a : #{a.clear()}\n\n" puts "clear b : #{b.clear()}\n\n" puts "clear b : #{c.clear()}\n\n" Output : clear a : {} clear b : {} clear b : {} Example #2: Ruby # Ruby code for clear() 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} puts "clear a : #{a.clear()}\n\n" puts "clear b : #{b.clear()}\n\n" puts "clear b : #{c.clear()}\n\n" Output : clear a : {} clear b : {} clear b : {} Comment More infoAdvertise with us Next Article Ruby | Hash eql? function K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Hash each() function Hash#each() is a Hash class method which finds the nested value which calls block once for each key in hash by passing the key-value pair as parameters. Syntax: Hash.each() Parameter: Hash values Return: calls block once for each key in hash otherwise Enumerator if no argument is passed. Example #1 2 min read Ruby | clear() function The clear() function in Ruby is used to remove all the elements of the given array and returns the array with no elements. Syntax: Array.clear Here Array is the input array whose elements are to be cleared. Parameters: This function does not accept any parameter. Returns: the array with no elements. 1 min read Ruby | clear() function The clear() function in Ruby is used to remove all the elements of the given array and returns the array with no elements. Syntax: Array.clear Here Array is the input array whose elements are to be cleared. Parameters: This function does not accept any parameter. Returns: the array with no elements. 1 min read Ruby | Hash eql? function Hash#eql?() is a Hash class method which checks whether the two Hash arrays are equal or not. Syntax: Hash.eql?() Parameter: Hash values Return: true - if two hash arrays are equal otherwise return false Example #1 : Ruby # Ruby code for Hash.eql?() method # declaring Hash value a = {a:100, b:200} # 2 min read Ruby | Hash any?() function any?() is a Hash class method which checks for the presence of a pattern and passes each element of the collection to the given block. Syntax: Hash.any?() Parameter: Hash for testing Return: true - if the block ever returns a value other than false or nil otherwise return false Example #1: Ruby # Ru 1 min read Ruby | Hash delete() function delete() is an Hash class method which deletes the key-value pair and returns the value from hash whose key is equal to key. Syntax: Hash.delete() Parameter: Hash array Return: value from hash whose key is equal to deleted key. Example #1: Ruby # Ruby code for delete() method # declaring Hash value 1 min read Like