Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Range#reverse_each

reverse_each {|element| ... } → self
reverse_each → an_enumerator

With a block given, passes each element of self to the block in reverse order:

Example
a = []
(1..4).reverse_each {|element| a.push(element) } # => 1..4
a # => [4, 3, 2, 1]

a = []
(1...4).reverse_each {|element| a.push(element) } # => 1...4
a # => [3, 2, 1]

With no block given, returns an enumerator.

Ruby version changes

  1. 3.3
See also #overlap? #size #minmax #step also in 4.1 · 4.0 · 3.4