Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Enumerable reverse_each() function

  • Last Updated : 05 Dec, 2019

The reverse_each() of enumerable is an inbuilt method in Ruby returns the elements of the temporary array. The temporary array contains the enumerable in reverse order. It returns an enumerator if no block is given.

Syntax: enu.reverse_each { |obj| block }

Parameters: The function accepts a block.

Return Value: It returns the elements in reverse order.

Example 1:






# Ruby program for reverse_each method in Enumerable
  
# Initialize 
enu = (1..10)
  
# Prints
enu.reverse_each { |obj| p obj%2==1 }

Output:

false
true
false
true
false
true
false
true
false
true

Example 2:




# Ruby program for reverse_each method in Enumerable
  
# Initialize 
enu = [1, 7, 10, 11]
  
# Prints
enu.reverse_each

Output:

Enumerator: [1, 7, 10, 11]:reverse_each
My Personal Notes arrow_drop_up
Recommended Articles
Page :