Skip to content

Commit 9e1b437

Browse files
committed
Fix a linter warning "Do not use unless with else"
1 parent 5b36167 commit 9e1b437

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/ruby/truffleruby/core/enumerable.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -525,33 +525,33 @@ def inject(initial=undefined, sym=undefined, &block)
525525
warn 'given block not used', uplevel: 1
526526
end
527527

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
535532

536533
each do
537534
o = Primitive.single_block_arg
538535
if Primitive.undefined? initial
539536
initial = o
540537
else
541-
initial = initial.__send__(sym, o)
538+
initial = yield(initial, o)
542539
end
543540
end
544-
545-
# Do the block version:
546-
# inject {|memo, operand| ... } -> object
547-
# inject(initial_operand) {|memo, operand| ... } -> object
548541
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+
549549
each do
550550
o = Primitive.single_block_arg
551551
if Primitive.undefined? initial
552552
initial = o
553553
else
554-
initial = yield(initial, o)
554+
initial = initial.__send__(sym, o)
555555
end
556556
end
557557
end

0 commit comments

Comments
 (0)