Skip to content

ambiguous-block-association

Rubysuspiciousno fixdefault: offruby/rubocop

Reports a call without parentheses whose last argument is a call with a braces block (expect { x }.to change { y }); also a do block that binds to the outer call while a block method is an argument.

A {} block binds to the nearest call and a do ... end block to the outermost one, so without parentheses it is easy to attach the block to a different method from the one that was meant, and the code runs without the block being used as intended.

To fix, add parentheses around the arguments.

Reported
puts [1].map { |x| x }
...
raise StandardError
...
ruby:
lint:
rules:
ambiguous-block-association: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line ambiguous-block-association in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/AmbiguousBlockAssociation full