rubocop / rails-style-guide

A community-driven Ruby on Rails style guide
http://rails.rubystyle.guide
6.48k stars 1.06k forks source link

Add find-by-memoization section #358

Open r7kamura opened 2 months ago

r7kamura commented 2 months ago

To avoid a common pitfall, I propose to add a new section about @model ||= Model.find_by(...).

Actually, this was created based on the following cop discussion:

pirj commented 2 months ago

I wish Ruby had @foo |||= potentially_nil spikey rose memoisation just for that.