Ruby | Hash any?() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 # Ruby code for any?() 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} # checking pattern puts "pattern : #{a.any?()}\n\n" puts "pattern : #{b.any?()}\n\n" Output : pattern : true pattern : true Example #2: Ruby # Ruby code for any?() method # declaring Hash value c = {} puts "pattern : #{c.any?}\n\n" Output : pattern : false Comment More infoAdvertise with us Next Article Ruby | Hash each() 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 | Hash flatten() function Hash#flatten() is a Hash class method which returns the one-dimensional flattening hash array. Syntax: Hash.flatten() Parameter: Hash values Return: one-dimensional flattening hash array Example #1 : Ruby # Ruby code for Hash.flatten() method # declaring Hash value a = {a:100, b:200} # declaring Has 2 min read Ruby | Hash empty? function Hash#empty?() is a Hash class method which checks whether the Hash array has any key-value pair. Syntax: Hash.empty?()Parameter: Hash valuesReturn: true - if no key value pair otherwise return false Example #1 :  Ruby # Ruby code for Hash.empty?() method # declaring Hash value a = {a:100, b:200} # 1 min read Ruby | Hash assoc() function assoc() is an Hash class method which searches an element through the Hash. Syntax: Hash.assoc() Parameter: Hashs for finding elements. Return: searches an element through the Hash Example #1: Ruby # Ruby code for assoc() method # declaring Hash value a = { "a" => 100, "b" = 1 min read Ruby | Hash clear() function 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 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 Like