mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
add symbol style to Enumerable#inject
This commit is contained in:
+7
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user