From: John Gabriele Date: 2006-07-05T14:48:45+09:00 Subject: Re: can I alias foo --> LongModuleName.foo? On 7/5/06, Sean O'Halpin wrote: > On 7/5/06, John Gabriele wrote: > > I'd like to save some typing and do: > > > > --------- code --------- > > module LongModuleName > > def LongModuleName.foo > > puts "..." > > end > > end > > > > # I don't want to have to keep typing out > > # LongModuleName.foo, so let's make a shortcut. > > alias foo LongModuleName.foo > > > > foo > > --------- /code --------- > > > > But Ruby doesn't like that alias line. Any way to get this nice > > shortcut to work? > > Forgive me if I'm missing something obvious, by why not just use: > > def foo;LongName.foo;end > > Regards, > Sean Redefining the method should work (as long as I pass all args along to the fully-qualified call). Thank you. Hadn't thought of that. But it turns out that, unfortunately, I'm more confused now than before... The module in question is an extension module (written in C). I'd thought that it was just a pile of *module* methods (like "foo" is in the above example). But, for some reason, if I do: include LongModuleName foo it actually works. The calls in the extension module code are set up using rb_define_module_function(...). It doesn't look like there are any instance methods in this module: irb:> LongModuleName.instance_methods ==> [] (Hm.. Why no Module.module_methods method?) Yet, still, inexplicably, I'm able to "include LongModuleName" and then just call the methods without prefixing them with the modules's name. Maybe this has turned into the subject of another post. Thanks. ---John