Sha256: 1a2d0d6c12c9df63fe4a2abf5efabf3b558ffd8a7ac17115c7d2feffa9b3f7e1
Contents?: true
Size: 628 Bytes
Versions: 15
Compression:
Stored size: 628 Bytes
Contents
module V8 module Util module Weakcell def weakcell(name, &block) unless storage = instance_variable_get("@#{name}") storage = instance_variable_set("@#{name}", Storage.new) end storage.access(&block) end class Storage def access(&block) if @ref @ref.object || populate(block) else populate(block) end end private def populate(block) occupant = block.call() @ref = Ref::WeakReference.new(occupant) return occupant end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems