Skip to content
Browse files

Merge pull request #533 from jstepien/enumerable-inject

More complete Enumerable#inject
  • Loading branch information
alex committed Mar 19, 2013
2 parents 3189bf9 + 0bf6683 commit 7c53873049e7c1a94a2273ae41a57a1664632e45
Showing with 19 additions and 8 deletions.
  1. +19 −3 lib-topaz/enumerable.rb
  2. +0 −5 spec/tags/core/enumerable/inject_tags.txt
@@ -18,9 +18,25 @@ def map

alias collect map

def inject(memo)
self.each do |x|
memo = (yield memo, x)
def inject(*args)
dropped = 0
meth = nil
case args.length
when 0
memo = self.first
dropped = 1
when 1
memo = args[0]
when 2
memo = args[0]
meth = args[1]
self.drop(dropped).each do |x|
if meth
memo = memo.send(meth, x)
memo = (yield memo, x)
@@ -1,7 +1,2 @@
fails:Enumerable#inject can take two argument
fails:Enumerable#inject ignores the block if two arguments
fails:Enumerable#inject can take a symbol argument
fails:Enumerable#inject without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator
fails:Enumerable#inject gathers whole arrays as elements when each yields multiple
fails:Enumerable#inject without inject arguments(legacy rubycon)
fails:Enumerable#inject returns nil when fails(legacy rubycon)

0 comments on commit 7c53873

Please sign in to comment.
You can’t perform that action at this time.