Skip to content
This repository
Browse code

remove Enumerable#each_with_object again

it come back occasionally in 367741e
  • Loading branch information...
commit 1922283177e92823e760720889a60e5a9576648f 1 parent ead2593
Sergey Nartimov authored December 23, 2011
21  activesupport/lib/active_support/core_ext/enumerable.rb
@@ -26,27 +26,6 @@ def sum(identity = 0, &block)
26 26
     end
27 27
   end
28 28
 
29  
-  # Iterates over a collection, passing the current element *and* the
30  
-  # +memo+ to the block. Handy for building up hashes or
31  
-  # reducing collections down to one object. Examples:
32  
-  #
33  
-  #   %w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase }
34  
-  #   # => {'foo' => 'FOO', 'bar' => 'BAR'}
35  
-  #
36  
-  # *Note* that you can't use immutable objects like numbers, true or false as
37  
-  # the memo. You would think the following returns 120, but since the memo is
38  
-  # never changed, it does not.
39  
-  #
40  
-  #   (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1
41  
-  #
42  
-  def each_with_object(memo)
43  
-    return to_enum :each_with_object, memo unless block_given?
44  
-    each do |element|
45  
-      yield element, memo
46  
-    end
47  
-    memo
48  
-  end unless [].respond_to?(:each_with_object)
49  
-
50 29
   # Convert an enumerable to a hash. Examples:
51 30
   #
52 31
   #   people.index_by(&:login)

0 notes on commit 1922283

Please sign in to comment.
Something went wrong with that request. Please try again.