Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
# 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
This paste will be private.
From the Design Piracy series on my blog: