Skip to content

Commit

Permalink
Merge pull request #591 from kachick/implement-enumerable-each_with_o…
Browse files Browse the repository at this point in the history
…bject

Implement Enumerable#each_with_object
  • Loading branch information
alex committed Apr 10, 2013
2 parents de8f9cf + 4109da9 commit d8f4097
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Authors
* Robin Schreiber
* Jan Stępień
* Jeremy Thurgood
* Kenichi Kamiya
8 changes: 8 additions & 0 deletions lib-topaz/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def each_with_index(&block)
end
end

def each_with_object(memo, &block)
return self.enum_for(:each_with_object, memo) unless block
self.each do |elm|
yield elm, memo
end
memo
end

def all?(&block)
self.each do |obj|
return false unless (block ? block.call(obj) : obj)
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/core/enumerable/each_with_object_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:Enumerable#each_with_object passes each element and its argument to the block
fails:Enumerable#each_with_object returns an enumerator if no block
fails:Enumerable#each_with_object gathers whole arrays as elements when each yields multiple
3 changes: 0 additions & 3 deletions spec/tags/core/enumerator/each_with_object_tags.txt

This file was deleted.

0 comments on commit d8f4097

Please sign in to comment.