Module: RUtilAnts
- Defined in:
- lib/rUtilAnts/GUI.rb,
lib/rUtilAnts/Misc.rb,
lib/rUtilAnts/Archive.rb,
lib/rUtilAnts/Logging.rb,
lib/rUtilAnts/Plugins.rb,
lib/rUtilAnts/Platform.rb,
lib/rUtilAnts/URLCache.rb,
lib/rUtilAnts/MySQLPool.rb,
lib/rUtilAnts/URLAccess.rb,
lib/rUtilAnts/ForeignProcess.rb,
lib/rUtilAnts/SingletonProxy.rb,
lib/rUtilAnts/URLHandlers/FTP.rb,
lib/rUtilAnts/URLHandlers/HTTP.rb,
lib/rUtilAnts/GUI/BugReportDialog.rb,
lib/rUtilAnts/URLHandlers/DataImage.rb,
lib/rUtilAnts/URLHandlers/LocalFile.rb,
lib/rUtilAnts/Platforms/unix/PlatformInfo.rb,
lib/rUtilAnts/Platforms/linux/PlatformInfo.rb,
lib/rUtilAnts/Platforms/cygwin/PlatformInfo.rb,
lib/rUtilAnts/Platforms/macosx/PlatformInfo.rb,
lib/rUtilAnts/Platforms/windows/PlatformInfo.rb
Overview
– Copyright © 2009 - 2012 Muriel Salvan ([email protected]) Licensed under the terms specified in LICENSE file. No warranty is provided. ++
Defined Under Namespace
Modules: Archive, ForeignProcess, GUI, Logging, Misc, MySQLPool, Platform, Plugins, URLAccess, URLCache
Class Method Summary collapse
-
.make_singleton_proxy(iSrcModule, oDstModule) ⇒ Object
Make public methods from a module accessible in another module, using a singleton as proxy.
Class Method Details
.make_singleton_proxy(iSrcModule, oDstModule) ⇒ Object
Make public methods from a module accessible in another module, using a singleton as proxy
- Parameters
-
iSrcModule (Module): Module to get public methods from
-
oDstModule (Module): Module that will encapsulate the singleton and route all public methods through that singleton
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rUtilAnts/SingletonProxy.rb', line 13 def self.make_singleton_proxy(iSrcModule, oDstModule) lSrcModuleConstName = iSrcModule.name.gsub(/\W/,'_') # Create the singleton class lSingletonClass = oDstModule.const_set("SingletonClassForModule__#{lSrcModuleConstName}", Class.new) lSingletonClass.class_eval("include #{iSrcModule}") # Instantiate it in the module lSymSingletonVarName = "@@__SingletonForModule__#{lSrcModuleConstName}".to_sym oDstModule.send(:class_variable_set, lSymSingletonVarName, lSingletonClass.new) # Create public methods from iSrcModule to oDstModule, using the singleton as a proxy iSrcModule.instance_methods.map { |iMethodName| iMethodName.to_sym }.each do |iSymMethodName| oDstModule.send(:define_method, iSymMethodName) do |*iArgs, &iBlock| oDstModule.send(:class_variable_get, lSymSingletonVarName).send(iSymMethodName, *iArgs, &iBlock) end end end |