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
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
# File 'lib/sup/util.rb', line 556
def method_missing meth, *a, &b
raise "no #{name} instance defined in method call to #{meth}!" unless defined? @instance
return nil if @instance.nil?
if meth.to_s[-1,1] == '='
class_eval "def self.#{meth}(a); @instance.send :#{meth}, a; end"
else
class_eval "def self.#{meth}(*a, &b); @instance.send :#{meth}, *a, &b; end"
end
@instance.send meth, *a, &b
end
|
Instance Method Details
#deinstantiate! ⇒ Object
555
|
# File 'lib/sup/util.rb', line 555
def deinstantiate!; @instance = nil; end
|
#init(*args) ⇒ Object
575
576
577
578
|
# File 'lib/sup/util.rb', line 575
def init *args
raise "there can be only one! (instance)" if instantiated?
@instance = new(*args)
end
|
553
|
# File 'lib/sup/util.rb', line 553
def instance; @instance; end
|
#instantiated? ⇒ Boolean
554
|
# File 'lib/sup/util.rb', line 554
def instantiated?; defined?(@instance) && !@instance.nil?; end
|