# Case 1 def show redirect_to 'error' and return if params.has?(:api_key) end # Redirected to /error # Case 2 def show redirect_to 'error' && return if params.has?(:api_key) end # Rendering show.html.erb
Case #1 is our expected result and case #2 is not. In case #2, "&& return" will not work because && has much higher precedence level.
So when rubocop suggests to change "and" to "&&" you need to simulate the result if it is what you want before replacing. At this point in time, rubocop has not provided a way to skip this warning for "and return" scenario. A simple way to hide the warning is to split the return call into another line. E.g.
def show unless params.has?(:api_key) redirect_to 'error' return end end