def memoize_function(*function_ids)
mc = @__memoize_cache__ ||= {}
function_ids.each do |method_id|
method_id = method_id.to_s.to_sym
orig_method = instance_method(method_id)
__send__(:define_method, method_id) do |*args|
if mc.key?(method_id) and result = mc[method_id][args]
result
else
(mc[method_id] ||= {})[args] = result = orig_method.bind(self).call(*args)
$DEBUG and warn "#{self.class} cached function #{method_id}(#{args.inspect unless args.empty?}) = #{result.inspect}"
end
result
end
end
end