On 3/8/07, Xavier N. [email protected] wrote:
I am trying to aliase a module method to some local alias (to ease
some template). I’ve tried a few variations of
alias escape_latex MyUtils.escape_latex
without luck so far. I could mixin the module or write a wrapper, but
I’d like to know how to accomplish that with alias, or that it is not
possible if that’s the case.
first of all, you need to use symbols for methods (actually, you just
refer to the names of the methods):
alias :escape_latex :MyUtils.escape_latex
Can you see the problem: how you’d write the symbol for
MyUtils.escape_latex? This is not the way.
Now, this is excerpt from Ryan D.’ Ruby QuickRef
(Ruby | zenspider.com | by ryan davis):
Aliasing
alias :new :old
alias_method :new, :old
Creates a new reference to whatever old referred to. old can be any
existing method, operator, global. It may not be a local, instance,
constant, or class variable.
The simple solution would be in this case (provided you don’t mind
including the other methods of the module):
include MyUtils
PS: I’ve tried
module TheModule
instance_eval “alias escape_latex MyUtils.escape_latex”
end
and I got:
(eval):1: parse error, unexpected ‘.’, expecting $
alias escape_latex MyUtils.escape_latex
^(pointing at the dot)
I don’t think it’d work, but I may be wrong, and will be glad if
somebody
will show the working code for this.