Sha256: 8f6dd8f17e2f89232e9e5e787928093321465b5f5e1d30d3181f85137e3c29df

Contents?: true

Size: 558 Bytes

Versions: 2

Compression:

Stored size: 558 Bytes

Contents

module ShortLived
  
  # TODO Explain better what to do.
  #
  class LifetimeMissingError < StandardError; end
  
  def self.included klass
    klass.extend ClassMethods
  end
  
  def initialize window
    super window
    
    raise ShortLived::LifetimeMissingError.new unless self.respond_to? :lifetime 
    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

2 entries across 2 versions & 1 rubygems

Version Path
gosu_extensions-0.1.10 lib/traits/short_lived.rb
gosu_extensions-0.1.9 lib/traits/short_lived.rb