-
-
Notifications
You must be signed in to change notification settings - Fork 284
Closed
Description
Is your feature request related to a problem? Please describe.
The unsafe auto correct for Rails/FindByOrAssignmentMemoization
added too many lines to a couple of admittedly bloated classes.
Describe the solution you'd like
When running the new Rails/FindByOrAssignmentMemoization
cop with the -A flag it will do the following:
Changes:
def product
@product ||= Product.find_by(code: params[:code])
end
To:
def product
if instance_variable_defined?(:@product)
@product
else
@product = Product.find_by(code: params[:code])
end
end
To save a few lines, I was wondering if the format could be changed to?
def product
return @product if instance_variable_defined?(:@product)
@product = Product.find_by(code: params[:code])
end
AlanGabbianelli
Metadata
Metadata
Assignees
Labels
No labels