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:
enu = ( 1 .. 10 )
enu.reverse_each { |obj| p obj% 2 == 1 }
|
Output:
false
true
false
true
false
true
false
true
false
true
Example 2:
enu = [ 1 , 7 , 10 , 11 ]
enu.reverse_each
|
Output:
Enumerator: [1, 7, 10, 11]:reverse_each
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...