Sha256: e581c5da4f4b3df39429ff0cdc2ff5d198c7c4d330d87f586af1586f9d0b6c0a
Contents?: true
Size: 860 Bytes
Versions: 33
Compression:
Stored size: 860 Bytes
Contents
module ShortLived extend Trait class LifetimeMissingError < RuntimeError def initialize super <<-MESSAGE A ShortLived thing must define method lifetime lifetime = nil, &block with either params lifetime 74 # some value or lifetime { 50 + rand(50) } # some block to define how long the thing should live until it is destroyed. MESSAGE end end def self.included klass klass.extend ClassMethods end def initialize window raise LifetimeMissingError.new unless self.respond_to? :lifetime super window threaded self.lifetime do self.destroy! end end module ClassMethods def lifetime lifetime = nil, &block block = lambda { lifetime } unless block_given? define_method :lifetime, &block end end end
Version data entries
33 entries across 33 versions & 1 rubygems