# Alias for Module Method

**URL:** <https://rubytalk.org/t/alias-for-module-method/64081>\
**Category:** ruby-talk\
**Created:** [8 November 2011 19:45 UTC](https://rubytalk.org/t/alias-for-module-method/64081 "2011-11-08T19:45:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Admin\_Tensor](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Admin\_Tensor](https://rubytalk.org/u/Admin_Tensor)\
**Post date:** [8 November 2011 19:45 UTC](https://rubytalk.org/t/alias-for-module-method/64081/1 "2011-11-08T19:45:02Z")

</div>

Hi,

Is there a way to have an alias for module method? This code does not  
work:

# ---------------------  
module MyModule  
&nbsp;&nbsp;def MyModule.func  
&nbsp;&nbsp;&nbsp;&nbsp;puts 'Hello'  
&nbsp;&nbsp;end

&nbsp;&nbsp;alias funcAlias func  
end

MyModule.funcAlias  
# ---------------------

I am using Ruby 1.9.2.

Thanks,

Bill

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![luke\_gruber](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@luke\_gruber](https://rubytalk.org/u/luke_gruber)\
**Post date:** [8 November 2011 20:18 UTC](https://rubytalk.org/t/alias-for-module-method/64081/2 "2011-11-08T20:18:30Z")

</div>

Hey,

Yeah, in your code Ruby tries to alias an instance method called :func  
defined in the module. Since it doesn't exist, it doesn't work. Alias  
and alias\_method only work on instance methods, but luckily singleton  
methods like :func in your example are really instance methods defined  
in the singleton class of MyModule.

module MyModule  
&nbsp;&nbsp;def MyModule.func  
&nbsp;&nbsp;&nbsp;&nbsp;puts 'Hello'  
&nbsp;&nbsp;end

&nbsp;&nbsp;class \<\< self # or, class \<\< MyModule  
&nbsp;&nbsp;&nbsp;&nbsp;alias funcAlias func  
&nbsp;&nbsp;end  
end

MyModule.funcAlias

Take care,

-Luke

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Admin\_Tensor](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Admin\_Tensor](https://rubytalk.org/u/Admin_Tensor)\
**Post date:** [8 November 2011 20:23 UTC](https://rubytalk.org/t/alias-for-module-method/64081/3 "2011-11-08T20:23:19Z")

</div>

Wow, it really works! Thanks a lot for the singleton class.

Regards,

Bill

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
