diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-10-19 21:16:18 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-10-19 21:16:18 +0900 |
| commit | 17278e8ca69d79f4d37e65830c95cc6004c2d8f5 (patch) | |
| tree | 9352429de6694a63699aafef6f411de505350404 /mrblib/enum.rb | |
| parent | fd949663d2229419a1e53e69351205cd27157653 (diff) | |
| download | mruby-17278e8ca69d79f4d37e65830c95cc6004c2d8f5.tar.gz mruby-17278e8ca69d79f4d37e65830c95cc6004c2d8f5.zip | |
add symbol style to Enumerable#inject
Diffstat (limited to 'mrblib/enum.rb')
| -rw-r--r-- | mrblib/enum.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/mrblib/enum.rb b/mrblib/enum.rb index 666ada294..29422716c 100644 --- a/mrblib/enum.rb +++ b/mrblib/enum.rb @@ -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 |
