hoodwink.d enhanced

Mon Oct 9

Expireable memoization

class Object def memoize(reload = false, storage = nil) storage = "@#{storage || __method__(1)}" if reload instance_variable_set(storage, nil) else if cache = instance_variable_get(storage) return cache end end instance_variable_set(storage, yield) end end module Kernel def __method__(depth = 0) caller[depth][/`([^']+)'/, 1] end end if RUBY_VERSION < '1.9' class WebPage def source(reload = false) memoize(reload) do # Download page end end end