Created
March 10, 2012 10:21
-
-
Save makaroni4/2011073 to your computer and use it in GitHub Desktop.
Inject using proc
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
class Array | |
def my_own_inject(proc) | |
temp = 0 | |
self.each do |e| | |
temp = proc.call(temp, e) | |
end | |
temp | |
end | |
end | |
proc = Proc.new {|sum, x| sum += x} | |
puts [1, 2, 3].my_own_inject(proc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment