#14591·rubocop

Write up useless / ambiguous flow control in lambdas

Author: forthrinCreated Oct 8, 2025Updated Sep 18, 2026
Labelsfeature request

Is your feature request related to a problem? Please describe.

ruby
n = lambda do
  print 'n'
  next
end

b = lambda do
  print 'b'
  break
end

2.times do
  n.call
  print it
end
print ' '

2.times do
  b.call
  print it
end
puts ' DONE'

An unseasoned programmer may think next and break will work in the calling scope, especially since there's no flow logic in the lambda, so they wouldn't make sense there in the first place.

However, it in fact works in the lambda, and furthermore has no function there since it's at the end of the scope.

Describe the solution you'd like

A cop should raise at least one eyebrow at the peculiarity.

Describe alternatives you've considered

This possibly even raises the question if the Ruby interpreter should raise an exception for meaningless flow control. (Unless someone knows an official statement from maintainers that flow control keywords are graceful by design)

Additional context

ruby      2025-08-01 30a20bc16
rubocop   2025-10-04 a08091813
System Version: macOS 15.6 (24G84)
Model Identifier: MacBookAir10,1