MJD was talking about Memoize. Here it is in Ruby:
module Memoize
def memoize(func_name)
cache = {}
(class<<elf; self; end).send(:define_method, func_name) { |*args|
return cache[args] if cache.has_key? args
cache[args] = super
}
end
end
There’s a lot of code in the Perl Memoize module; maybe it does other things—I haven’t really looked. Oh, and here’s this Memoize module from RAA. I’m some months late. :-)