The Pug Automatic

Rose memoization

Written January 26, 2016. Tagged Ruby.

"Memoization" is caching the results of expensive method calls for speed.

In Ruby, this is often implemented something like this:

def my_expensive_method
@my_expensive_method ||= one + two * three
end

or

def my_expensive_method
@my_expensive_method ||= begin
one
two
three
end
end

Clearly this needs a name.

I've always thought of it as "rose memoization", because of the @ ||= pattern. It looks like an ASCII rose.

I was amazed not to find any (any!) Google results for that term, so now this post exists.

Are there any other terms in use for this construct?

(Parenthetically, I recommend memoit for any non-trivial memoization. I also recommend not memoizing at all in many cases.)