Method: Treebis::PersistentDotfile::ClassMethods#persistent_delegate_to

Defined in:
lib/treebis.rb

#persistent_delegate_to(mod) ⇒ Object



901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
# File 'lib/treebis.rb', line 901

def persistent_delegate_to(mod)
  if instance_variable_defined?('@persistent_delegate') # rcov
    @persistent_delegate
  else
    @persistent_delegate = begin
      mm = Module.new
      str = "#{self}::PersistentDotfileDelegate"
      const_set('PersistentDotfileDelegate', mm)
      class << mm; self end.send(:define_method,:inspect){str}
      buck = self
      DelegatedMethods.each do |meth|
        mm.send(:define_method, meth){|*a| buck.send(meth,*a) }
      end
      mm
    end
  end
  mod.extend(@persistent_delegate)
  mod.send(:include, @persistent_delegate)
end