This cop checks for methods called on a do...end block. The point of this check is that it's easy to miss the call tacked on to the block when reading code.
@example
a do
b
end.c
# File lib/rubocop/cop/style/method_called_on_do_end_block.rb, line 17 def on_block(node) method, _args, _body = *node # If the method that is chained on the do...end block is itself a # method with a block, we allow it. It's pretty safe to assume that # these calls are not missed by anyone reading code. We also want to # avoid double reporting of offenses checked by the # MultilineBlockChain cop. ignore_node(method) end
# File lib/rubocop/cop/style/method_called_on_do_end_block.rb, line 27 def on_send(node) return if ignored_node?(node) receiver, _method_name, *_args = *node return unless receiver && receiver.type == :block && receiver.loc.end.is?('end') range = Parser::Source::Range.new(receiver.loc.end.source_buffer, receiver.loc.end.begin_pos, node.loc.expression.end_pos) add_offense(nil, range) end
Generated with the Darkfish Rdoc Generator 2.