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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
# File 'lib/sup/util.rb', line 641
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
640
|
# File 'lib/sup/util.rb', line 640
def deinstantiate!; @instance = nil; end
|
#init(*args) ⇒ Object
660
661
662
663
|
# File 'lib/sup/util.rb', line 660
def init *args
raise "there can be only one! (instance)" if instantiated?
@instance = new(*args)
end
|
638
|
# File 'lib/sup/util.rb', line 638
def instance; @instance; end
|
#instantiated? ⇒ Boolean
639
|
# File 'lib/sup/util.rb', line 639
def instantiated?; defined?(@instance) && !@instance.nil?; end
|