Skip to content

Instantly share code, notes, and snippets.

@tjeden
Created November 13, 2012 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjeden/4066769 to your computer and use it in GitHub Desktop.
Save tjeden/4066769 to your computer and use it in GitHub Desktop.
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