Ruby Memoize
def memoize(method_name) cache = {} define_method(method_name) do |*args| cache[args] ||= yield(*args) end end memoize(:add) {|a,b| p "calc #{a} and #{b}" a+b } p add(23,45) p add(23,45)