ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

Add rule against memoizing possibly falsely values

Open sambostock opened this issue 5 years ago • 1 comments

This adds a rule elaborating on some of the pitfalls of ||=.

"Avoid using ||= to initialize boolean variables" provides a good explanation about false not being safe to use with ||=, but cases where the value can be nil (e.g. not found) should also be considered.


Follow up to discussion in https://github.com/Shopify/ruby-style-guide/pull/193/files#r490432383

sambostock avatar Sep 21 '20 17:09 sambostock

Agreed with @rafaelfranca. Since this was inspired by the existing rule about using ||= to assign boolean values to variables, we may need to rephrase the existing rule better in order to avoid confusion. In any case I don't think we can (or should) put restrictions about using ||= with nil. I don't see any stylistic problems erupting from that use.

volmer avatar Sep 21 '20 18:09 volmer