@unknownuser said:
... I tried various flavors of the alias and alias_method keywords, but those don't seem to work with modules. I'm certain there's a way to do it, but I thought I'd ask here before diving into my Ruby books.
Yes.. it's weird that alias doesn't work with modules.
But this is even weirder. To alias modules, you instead use the object= method.
Example aliasing of Sketchup module: (At Ruby Console type the following, where ">>" is resulting output.)
Sketchup.class
>> Module
Sketchup.object_id
>> 43353420
# remember this id...
# now alias the module
SU = Sketchup
>> Sketchup
SU.class
>> Module
SU.object_id
>> 43353420
# it's the SAME exact id
# test it...
SU.version
>> 7.1.6087
I would think that we must be careful what namespace the alias constant is declared within. If the above statement "SU = Skecthup" was declared inside a module, or a class, it would only be accessible within that namespace, or must be qualified to be accessed.
For example, say you used that alias assignment within a module named "Configurator", in order to access the alias from outside, you'd need to qualify it with:
Configurator::SU.methodcall
However.. if you wished the alias to have global public access, you'd need to declare it outside ALL modules, in the objectspace. (Similar to typing it at the console.)
BUT... what if for control purposes (ie, conditional loading,) you needed to have the statement inside a class or module?
I think in this case, remember the Kernel.eval() method, and the fact that module Kernel is included in every object. That means that the containing module has it's own copy of eval. So you cannot call just eval (unqualified,) because you'd be calling the local module's copy of eval.
To do it from within a module (or class,) you must qualify the call:
if situation then Kernel.eval("SU = Sketchup");
Then the alias constant is global.