The rules says:
A ||= B assigns B to A only if A is nil or false
YES, especially when doing simple memoization technique. Lets consider simple case:
@a ||= 2 # correct, assigns 2 to @a and returns on each method call
@a ||= nil # memoization doesn't work as expected. It assigns nil to @a each time the method gets called!
Here you can find more sophisticated example with a way of how to handle a fix for it:
TIL, or Today I Learned, is where our developers share the best tech stuff they found every day. You can find smart solutions for some issues, useful advice and anything which will make your developer life easier.
Photo by Andrew Neel on Unsplash