Use a guard clause instead of wrapping the code inside a conditional expression
@example
# bad def test if something work end end # good def test return unless something work end # also good def test work if something end
# File lib/rubocop/cop/style/guard_clause.rb, line 33 def on_def(node) _, _, body = *node return unless body if if?(body) check_if_node(body) elsif body.type == :begin expressions = *body last_expr = expressions.last check_if_node(last_expr) if if?(last_expr) end end
Generated with the Darkfish Rdoc Generator 2.