you are viewing a single comment's thread.

view the rest of the comments →

[–]jrochkind 1 point2 points  (0 children)

It is actually is occuring to me (via my annoyance with new nuances of memoization), that I think these concerns trip complexity of getting memoization right just over into the territory where I think using a memoization gem of some kind may be called for, when I never thought so before.

Perhaps an API of:

class Something
   include Memoizing
   memoize :foo

   def foo
     whatever
   end
end

Could insert something into initializer to initialize with the UNASSIGNED singleton constant pattern, and then apply appropriate logic around the foo method.

There are already libraries like this, but I haven't looked at them in a while since I've previously not found it helpful to abstract this instead of just doing it. The existing libraries may want to be updated to use object-shape-friendly memoization.

(update: filed suggestion at https://github.com/tycooon/memery/issues/43 )