Skip to content

Instantly share code, notes, and snippets.

@coreyward
Created January 16, 2011 03:50
Show Gist options
  • Save coreyward/781539 to your computer and use it in GitHub Desktop.
Save coreyward/781539 to your computer and use it in GitHub Desktop.
An implementation of Ruby's inject method, written in Ruby (for learning/teaching purposes)
class Array
def my_inject (accumulator = 0, &block)
self.each do |item|
accumulator = block.call(accumulator, item)
end
accumulator
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment