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:
a = { "a" => 100 , "b" => 200 }
b = { "a" => 100 }
c = { "a" => 100 , "c" => 300 , "b" => 200 }
puts "pattern : #{a.any?()}\n\n"
puts "pattern : #{b.any?()}\n\n"
|
Output :
pattern : true
pattern : true
Example #2:
c = {}
puts "pattern : #{c.any?}\n\n"
|
Output :
pattern : false
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...