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



511
512
513
514
515
516
517
518
519
520
521
# File 'lib/sup/util.rb', line 511

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



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

def deinstantiate!; @instance = nil; end

#init(*args) ⇒ Object



522
523
524
525
# File 'lib/sup/util.rb', line 522

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

#instanceObject



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

def instance; @instance; end

#instantiated?Boolean

Returns:

  • (Boolean)


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

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