Memoize method in Ruby