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 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 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 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
Recommended Posts:
- Ruby | Enumerable max() function
- Ruby | Enumerable min() function
- Ruby | Enumerable none?() function
- Ruby | Enumerable one? function
- Ruby | Enumerable map() function
- Ruby | Enumerable sum() function
- Ruby | Enumerable take() function
- Ruby | Enumerable any? function
- Ruby | Enumerable first() function
- Ruby | Enumerable each_witth_object() function
- Ruby | Enumerable entries() function
- Ruby | Enumerable sort() function
- Ruby | Enumerable find_all() function
- Ruby | Enumerable detect() function
- Ruby | Enumerable partition() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

