Ruby | Enumerable all? function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 returns false. Syntax enu.all? { |obj| block } or enu.all?(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 none of the objects are false or nil. Return Value: It returns a boolean value. Example #1:: Ruby # Ruby program for all? method in Enumerable # Initialize an enumerable enu1 = [10, 19, 18] # checks if all numbers are greater # than 4 or not res1 = enu1.all? { |num| num>4} # prints the result puts res1 # ch__LINE__ecks if all numbers are greater # than 4 or not res2 = enu1.all? { |num| num>=15} # prints the result puts res2 Output: true false Example 2: Ruby # Ruby program for all? method in Enumerable # Initialize an enumerable enu1 = [10, 19, 20] # Checks res1 = enu1.all?(Numeric) # prints the result puts res1 # Initialize enu2 = [nil, nil] # Checks res2 = enu2.all? # prints the result puts res2 Output: true false Comment More infoAdvertise with us Next Article Ruby | Enumerable all? function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Enumerable-class Similar Reads Ruby | Enumerable any? function 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 an 2 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 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 collect() function The collect() 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).collect { |obj| block } Parameters 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 drop() function The drop() of enumerable is an inbuilt method in Ruby returns the rest elements in the enumerator after dropping the first N elements. Syntax: block.drop(N) Parameters: The function takes N which signifies the number of elements to be dropped. Return Value: It returns the rest elements after droppin 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 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 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 Like