提交 8d1d813b 编写于 作者: J Jeremy Kemper

Simplify Enumerable#each_with_object

上级 051bab5b
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册