Memoization
Memoization is a technique for performance optimization. It is, essentially, calculating a value once and then caching it within an object for the duration of its use.
Memoization comes from the Latin word โmemorandumโ, meaning โto be rememberedโ.
(Sourced from Jason Swettโs post on memoization)
class Product
def price
expensive_calculation
end
def memoized_price
@memoized_price || expensive_calculation
end
def expensive_calculation
sleep 1
500
end
end