Created
January 16, 2011 03:50
-
-
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)
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
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