@@ -525,33 +525,33 @@ def inject(initial=undefined, sym=undefined, &block)
525
525
warn 'given block not used' , uplevel : 1
526
526
end
527
527
528
- unless Primitive . undefined? ( sym ) && block_given?
529
- # Do the sym version:
530
- # inject(symbol) -> object
531
- # inject(initial_operand, symbol) -> object
532
-
533
- sym , initial = initial , undefined if Primitive . undefined? ( sym )
534
- sym = sym . to_sym
528
+ if Primitive . undefined? ( sym ) && block_given?
529
+ # Do the block version:
530
+ # inject {|memo, operand| ... } -> object
531
+ # inject(initial_operand) {|memo, operand| ... } -> object
535
532
536
533
each do
537
534
o = Primitive . single_block_arg
538
535
if Primitive . undefined? initial
539
536
initial = o
540
537
else
541
- initial = initial . __send__ ( sym , o )
538
+ initial = yield ( initial , o )
542
539
end
543
540
end
544
-
545
- # Do the block version:
546
- # inject {|memo, operand| ... } -> object
547
- # inject(initial_operand) {|memo, operand| ... } -> object
548
541
else
542
+ # Do the sym version:
543
+ # inject(symbol) -> object
544
+ # inject(initial_operand, symbol) -> object
545
+
546
+ sym , initial = initial , undefined if Primitive . undefined? ( sym )
547
+ sym = sym . to_sym
548
+
549
549
each do
550
550
o = Primitive . single_block_arg
551
551
if Primitive . undefined? initial
552
552
initial = o
553
553
else
554
- initial = yield ( initial , o )
554
+ initial = initial . __send__ ( sym , o )
555
555
end
556
556
end
557
557
end
0 commit comments