Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Created October 29, 2014 19:34
Show Gist options
  • Save davidbalbert/35ed222447975e247265 to your computer and use it in GitHub Desktop.
Save davidbalbert/35ed222447975e247265 to your computer and use it in GitHub Desktop.
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