Xavier Noria
3/9/2007 2:33:00 AM
On Mar 9, 2007, at 12:10 AM, dseiler@etceteraedutainment.com wrote:
> On Mar 8, 5:34 am, Xavier Noria <f...@hashref.com> 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.
>
> It's possible, sort of. Try
>
> module TheModule
> instance_eval "alias escape_latex MyUtils.escape_latex"
> end
>
> I use a similar technique (originally suggested by Minero Aoki,
> according to my notes) to replace Thread.critical and
> Thread.critical=. I've only tested it in 1.8.2 but I don't think
> anything's broken it since then.
I don't understand that technique (it is not working here). In fact
what I don't understand is alias.
In irb we can do
alias foo sprintf
Why can't we say
alias foo Math.sqrt
? Having a quick glance at eval.c I think the problem is that alias
is syntax (that's why it does not need a comma between its
"arguments") and I guess here's the key:
case NODE_ALIAS:
if (NIL_P(ruby_class)) {
rb_raise(rb_eTypeError, "no class to make alias");
}
rb_alias(ruby_class, rb_to_id(rb_eval(self, node->u1.node)),
rb_to_id(rb_eval(self, node->u2.node)));
-- fxn