Ruby | Enumerable any? function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The any?() of enumerable is an inbuilt method in Ruby returns a boolean value if any of the object in the enumerable satisfies the given condition, else it returns false. Syntax enu.any? { |obj| block } or enu.any?(pattern) Parameters: The function takes two types of parameters, one is the object and the block, while the other is the pattern. In case nothing is passed, it assumes to be default object and block which returns true if any of the objects are false or nil. Return Value: It returns a boolean value. Example 1: ruby # Ruby program for any? method in Enumerable # Initialize an enumerable enu1 = [10, 19, 18] # checks if any numbers are greater # than 13 or not res1 = enu1.any? { |num| num>13} # prints the result puts res1 res2 = enu1.any? { |num| num>=20} # prints the result puts res2 Output: true false Example 2: ruby # Ruby program for any? method in Enumerable # Initialize an enumerable enu1 = [10, 19, 20] # Checks res1 = enu1.any?(Numeric) # prints the result puts res1 # Initialize enu2 = [nil, 10] # Checks res2 = enu2.any? # prints the result puts res2 Output: true true Comment More infoAdvertise with us Next Article Ruby | Enumerable any? function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Enumerable-class Similar Reads Ruby | Enumerable all? function The all?() of enumerable is an inbuilt method in Ruby returns a boolean value true if all the objects in the enumerable satisfies the given condition, else it returns false. If a pattern is given, it compares with the pattern, and returns true if all of them are equal to the given pattern, else it r 2 min read Ruby | Enumerable to_a() function The to_a() of enumerable is an inbuilt method in Ruby returns an array containing all the items of the enumerable. Syntax: enu.to_a() Parameters: The function does not accepts any parameter. Return Value: It returns an array. Example #1: Ruby # Ruby program for to_a method in Enumerable # Initialize 1 min read Ruby | Enumerable count() function The count() of enumerable is an inbuilt method in Ruby returns the number of elements in the enumerable, or the number of elements that are equal to a given element, or the number of items which satisfies the condition in the given block. Syntax: block.count { |obj| block } or block.count(element) P 1 min read Ruby | Enumerable cycle() function The cycle() of enumerable is an inbuilt method in Ruby calls block for each element of enum repeatedly the given numbers times or forever if none or nil is given. If a negative numbers is given or the collection is empty, it does nothing. It returns nil if the loop has finished without getting inter 1 min read Ruby | Enumerable entries() function The entries() of enumerable is an inbuilt method in Ruby returns the items in the enumerable. Syntax: enu.entries Parameters: The function does not takes any parameter. Return Value: It returns the items in the enum. Example 1: ruby # Ruby program for entries method in Enumerable # Initialize enu = 1 min read Ruby | Enumerable map() function The map() of enumerable is an inbuilt method in Ruby returns a new array with the results of running block once for every element in enum. The object is repeated every time for each enum. In case no object is given, it return nil for each enum. Syntax: (r1..r2).map { |obj| block } Parameters: The fu 1 min read Ruby | Enumerable sum() function The sum() of enumerable is an inbuilt method in Ruby returns the sum of all the elements in the enumerable. If a block is given, the block is applied to the enumerable, then the sum is computed. If the enumerable is empty, it returns init. Syntax: enu.sum { |obj| block } Parameters: The function acc 1 min read Ruby | Enumerable max() function The max() of enumerable is an inbuilt method in Ruby returns the maximum elements or an array containing the maximum N elements in the enumerable. When no block is given, it assumes all elements to be self comparable, but when the block is given then it is compared using . Syntax: enu.max(n) { |a, b 1 min read Ruby | Enumerable min() function The min() of enumerable is an inbuilt method in Ruby returns the minimum elements or an array containing the minimum N elements in the enumerable. When no block is given, it assumes all elements to be self comparable, but when the block is given then it is compared using . Syntax: enu.min(n) { |a, b 1 min read Ruby | Enumerable find_all() function The find_all() of enumerable is an inbuilt method in Ruby returns the items in the enumerable which satisfies the given condition in the block. It returns an enumerator if no block is given. Syntax: enu.find_all { |obj| block } Parameters: The function takes a block whose condition is used to find t 1 min read Like