Sha256: 279a8bc6af269ca229ac81b9f6a610d435d9e004ac66619988cb22b5008c2b81
Contents?: true
Size: 555 Bytes
Versions: 1
Compression:
Stored size: 555 Bytes
Contents
module Memoize MEMOIZE_VERSION = "1.2.2" # Memoize the method +name+. If +file+ is provided, then the method results # are stored on disk as well as in memory. def memoize(name, file=nil) cache = File.open(file, "rb"){ |io| Marshal.load(io) } rescue {} (class<<self; self; end).send(:define_method, name) do |*args| unless cache.has_key?(args) cache[args] = super File.open(file, "wb+"){ |f| Marshal.dump(cache, f) } if file end cache[args] end cache end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
memoize-1.2.2 | lib/memoize.rb |