Trivial optimization for Enumerable#each_with_object

This commit is contained in:
Marc-Andre Lafortune
2011-07-23 15:41:55 -04:00
parent 816abecf90
commit f061ffd9f4

View File

@@ -76,10 +76,10 @@ module Enumerable
#
# (1..5).each_with_object(1) { |value, memo| memo *= value } # => 1
#
def each_with_object(memo, &block)
def each_with_object(memo)
return to_enum :each_with_object, memo unless block_given?
each do |element|
block.call(element, memo)
yield element, memo
end
memo
end unless [].respond_to?(:each_with_object)