Skip to content

Commit 5e7ce29

Browse files
committed
Refactor and simplify a bit the check to warn in Enumerable#inject
1 parent 4ceb4da commit 5e7ce29

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,15 @@ def inject(initial=undefined, sym=undefined, &block)
510510
return Primitive.array_inject(self, initial, sym, block)
511511
end
512512

513+
if !Primitive.undefined?(sym) && block_given?
514+
warn 'given block not used', uplevel: 1
515+
end
516+
513517
if !block_given? or !Primitive.undefined?(sym)
514518
if Primitive.undefined?(sym)
515519
raise ArgumentError, 'no block or symbol given' if Primitive.undefined?(initial)
516520
sym = initial
517521
initial = undefined
518-
else
519-
warn 'given block not used', uplevel: 1 if block_given?
520522
end
521523

522524
# Do the sym version

0 commit comments

Comments
 (0)