Memoization techniques in Ruby