How to iterate through an array starting from the last element? (Ruby) How to iterate through an array starting from the last element? (Ruby) arrays arrays

How to iterate through an array starting from the last element? (Ruby)


Ruby is smart

a = [ "a", "b", "c" ]a.reverse_each {|x| print x, " " }


array.reverse.each { |x| puts x }


In case you want to iterate through a range in reverse then use:

(0..5).reverse_each do |i|  # do somethingend