Created
October 29, 2014 19:34
-
-
Save davidbalbert/35ed222447975e247265 to your computer and use it in GitHub Desktop.
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
module Enumerable | |
def reductions(sym = nil, &block) | |
raise LocalJumpError, "no block given" unless sym || block | |
if sym | |
block = sym.to_proc | |
end | |
arr = to_a | |
arr[1..-1].reduce([arr.first]) do |acc, o| | |
acc << block.call(acc.last, o) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment