# Can I alias foo --\> LongModuleName.foo?

**URL:** <https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133>\
**Category:** Ruby\
**Created:** [July 5, 2006, 7:12am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133 "2006-07-05T07:12:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [July 5, 2006, 7:12am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133/1 "2006-07-05T07:12:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [July 5, 2006, 7:24am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133/2 "2006-07-05T07:24:54Z")

</div>

2006/7/5, John G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’d like to save some typing and do:
> 
> --------- code ---------  
> module LongModuleName  
> def LongModuleName.foo

You can save some typing here by doing

def self.foo

This is also safer with regard to changes in the module’s name.

> But Ruby doesn’t like that alias line. Any way to get this nice  
> shortcut to work?

def foo() LogModuleName.foo end

robert

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [July 5, 2006, 7:28am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133/3 "2006-07-05T07:28:03Z")

</div>

On 7/5/06, John G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> # 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

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [July 5, 2006, 8:01am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133/4 "2006-07-05T08:01:32Z")

</div>

On 7/5/06, John G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [snip]
> 
> It doesn’t look like there are any instance methods in this module:
> 
> irb:\> LongModuleName.instance\_methods  
> ==\> []
> 
> (Hm… Why no Module.module\_methods method?)

Ok. I see. Object#methods.

LongModuleName.methods show’s em all. So, they seem to be all “module  
methods” (rather than instance methods).

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [July 5, 2006, 8:32am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133/5 "2006-07-05T08:32:48Z")

</div>

On 7/5/06, I wrote:

> [snip]
> 
> 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.

Indeed, it has. Started a new thread with the subject, “module methods  
acting like instance methods in extension module”

Thanks,  
—John

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [July 5, 2006, 7:49am UTC](https://www.ruby-forum.com/t/can-i-alias-foo-longmodulename-foo/97133/6 "2006-07-05T07:49:21Z")

</div>

On 7/5/06, Sean O’Halpin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > # I don’t want to have to keep typing out
> 
> 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
