Module: Singleton::ClassMethods

Defined in:
lib/sup/util.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *a, &b) ⇒ Object



600
601
602
603
604
605
606
607
608
609
610
# File 'lib/sup/util.rb', line 600

def method_missing meth, *a, &b
  raise "no #{name} instance defined in method call to #{meth}!" unless defined? @instance

  ## if we've been deinstantiated, just drop all calls. this is
  ## useful because threads that might be active during the
  ## cleanup process (e.g. polling) would otherwise have to
  ## special-case every call to a Singleton object
  return nil if @instance.nil?

  @instance.send meth, *a, &b
end

Instance Method Details

#deinstantiate!Object



599
# File 'lib/sup/util.rb', line 599

def deinstantiate!; @instance = nil; end

#init(*args) ⇒ Object



611
612
613
614
# File 'lib/sup/util.rb', line 611

def init *args
  raise "there can be only one! (instance)" if instantiated?
  @instance = new(*args)
end

#instanceObject



597
# File 'lib/sup/util.rb', line 597

def instance; @instance; end

#instantiated?Boolean

Returns:

  • (Boolean)


598
# File 'lib/sup/util.rb', line 598

def instantiated?; defined?(@instance) && !@instance.nil?; end