Skip to content

Instantly share code, notes, and snippets.

@makaroni4
Created March 10, 2012 10:21
Show Gist options
  • Save makaroni4/2011073 to your computer and use it in GitHub Desktop.
Save makaroni4/2011073 to your computer and use it in GitHub Desktop.
Inject using proc
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