Created
November 13, 2012 16:28
-
-
Save tjeden/4066769 to your computer and use it in GitHub Desktop.
This file contains 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
module Enumerable | |
def inject_with_index(sum = 0) | |
each_with_index do |e, i| | |
sum = yield(sum, e , i) | |
end | |
sum | |
end | |
end | |
puts ['a', 'b', 'c', 'd'].inject_with_index { |a, e, i| a + i } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment