Commit 17278e8c authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

add symbol style to Enumerable#inject

parent fd949663
......@@ -199,7 +199,12 @@ module Enumerable
#
# ISO 15.3.2.2.11
def inject(*args, &block)
raise ArgumentError, "too many arguments" if args.size > 2
raise ArgumentError, "too many arguments" if args.size > 3
if Symbol === args[-1]
sym = args[-1]
block = ->(x,y){x.send(sym,y)}
args.pop
end
if args.empty?
flag = true # no initial argument
result = nil
......@@ -218,6 +223,7 @@ module Enumerable
}
result
end
alias reduce inject
##
# Alias for collect
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment