Simplify Enumerable#each_with_object
This commit is contained in:
parent
051bab5bd2
commit
8d1d813b66
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user