Module: Redwood::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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
|
# File 'lib/sup/util.rb', line 593
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
592
|
# File 'lib/sup/util.rb', line 592
def deinstantiate!; @instance = nil; end
|
#init(*args) ⇒ Object
612
613
614
615
|
# File 'lib/sup/util.rb', line 612
def init *args
raise "there can be only one! (instance)" if instantiated?
@instance = new(*args)
end
|
590
|
# File 'lib/sup/util.rb', line 590
def instance; @instance; end
|
#instantiated? ⇒ Boolean
591
|
# File 'lib/sup/util.rb', line 591
def instantiated?; defined?(@instance) && !@instance.nil?; end
|