From: Rick DeNatale Date: 2007-03-10T01:19:33+09:00 Subject: Re: how to aliase a module method? On 3/8/07, Xavier Noria wrote: > On Mar 9, 2007, at 12:10 AM, dseiler@etceteraedutainment.com wrote: > > > On Mar 8, 5:34 am, Xavier Noria 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 Because alias requires that both arguments be names (or symbols), Note that it's not a method but is directly performed by the ruby interpreter. irb(main):001:0> alias foo Math.sqrt SyntaxError: compile error (irb):1: parse error, unexpected '.', expecting $ alias foo Math.sqrt ^ from (irb):1 You're not even getting to eval.c, it's failing to parse. Module#alias_method requires that it's aruments be symbols cooresponding to the name. The other problem is that you are trying to make a name in a different scope than the name you are aliasing. As far as I can see this isn't possible. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/