rubocop-rails
rubocop-rails copied to clipboard
Allow use of instance variables for advanced memoization in Rails/HelperInstanceVariable
Is your feature request related to a problem? Please describe.
When I use advanced memoization techniques in a helper method, it gets flagged by Rails/HelperInstanceVariable.
Describe the solution you'd like
I'd like Rails/HelperInstanceVariable to accept assignment to instance variables for memoization purposes, i.e., it should allow methods like the following:
def foo
return @foo if defined?(@foo)
@foo ||= expensive_calculation_of_foo_that_can_actually_return_nil_value(bar, baz)
end
Describe alternatives you've considered
I considered moving the method elsewhere, but it doesn't make sense for its location to be dependent on using memoization or not.
Additional context
Shamelessly extended the following: https://github.com/rubocop/rubocop-rails/issues/311