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 code for any?() method # declaring Hash valuea = { "a" => 100, "b" => 200 } # declaring Hash valueb = {"a" => 100} # declaring Hash valuec = {"a" => 100, "c" => 300, "b" => 200} # checking patternputs "pattern : #{a.any?()}\n\n" puts "pattern : #{b.any?()}\n\n" |
Output :
pattern : true pattern : true
Example #2:
# Ruby code for any?() method # declaring Hash valuec = {} puts "pattern : #{c.any?}\n\n" |
Output :
pattern : false


.png)