class RuboCop::Cop::Lint::EnsureReturn
end
do_something_else
ensure
do_something
begin
# good
@example
end
return
do_something_else
ensure
do_something
begin
# bad
@example
and the exception will be silently thrown away as if it were rescued.
as the return will take precedence over any exception being raised,
Explicit return from an ensure block alters the control flow
This cop checks for return from an ensure block.
def on_ensure(node)
def on_ensure(node) ensure_body = node.body return unless ensure_body ensure_body.each_node(:return) do |return_node| add_offense(return_node) end end