Sha256: 49cc06a85226b7742695135deffd6b4938a5b0f1a9bba39b6bb8336a6d9df56d
Contents?: true
Size: 759 Bytes
Versions: 16
Compression:
Stored size: 759 Bytes
Contents
module Kernel # Object#cache is essentially like Module#memoize except # it can also be used on singleton/eigen methods. # OTOH, memoize's implementation is arguably better for it's # use of #bind instead of #alias. Eventually the two implmenations # will be reconciled with a single implmentation. def cache m = nil if m (Module === self ? self : (class << self; self; end)).module_eval <<-code alias_method '__#{ m }__', '#{ m }' def #{ m }(*__a__,&__b__) c = cache['#{ m }'] k = [__a__,__b__] if c.has_key? k c[k] else c[k] = __#{ m }__(*__a__,&__b__) end end code end @cache ||= Hash::new{|h,k| h[k]={}} end end
Version data entries
16 entries across 16 versions & 1 rubygems