Permalink
Browse files

Simplify Enumerable#each_with_object

  • Loading branch information...
1 parent 051bab5 commit 8d1d813b66d626dfaf82fa360907c7bf681180e5 @jeremy jeremy committed Mar 21, 2009
Showing with 3 additions and 4 deletions.
  1. +3 −4 activesupport/lib/active_support/core_ext/enumerable.rb
@@ -77,11 +77,10 @@ def sum(identity = 0, &block)
# (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1
#
def each_with_object(memo, &block)
- returning memo do |m|
- each do |element|
- block.call(element, m)
- end
+ each do |element|
+ block.call(element, memo)
end
+ memo
end unless [].respond_to?(:each_with_object)
# Convert an enumerable to a hash. Examples:

0 comments on commit 8d1d813

Please sign in to comment.