Last active
December 23, 2015 15:39
-
-
Save burtlo/6657015 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[:a,:b,:c].reverse_each.with_index do |item,index| | |
puts "#{item} #{index}" | |
end | |
# c 0 | |
# b 1 | |
# a 2 | |
module Enumerable | |
def each_with_reverse_index | |
each_with_index do |item,index| | |
countdown_index = length - 1 - index | |
yield item, countdown_index | |
end | |
end | |
end | |
[:a,:b,:c].each_with_reverse_index do |item,index| | |
puts "#{item} #{index}" | |
end | |
# a 2 | |
# b 1 | |
# c 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want output like the following: