# Aliases in ROR (for an instance)

**URL:** <https://www.ruby-forum.com/t/aliases-in-ror-for-an-instance/121366>\
**Category:** Rails\
**Created:** [November 27, 2007, 10:09am UTC](https://www.ruby-forum.com/t/aliases-in-ror-for-an-instance/121366 "2007-11-27T10:09:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [November 27, 2007, 10:09am UTC](https://www.ruby-forum.com/t/aliases-in-ror-for-an-instance/121366/1 "2007-11-27T10:09:26Z")

</div>

hi,

following situation:

class Item \< ActiveRecord::Base  
alias :newmeth :oldmeth  
end

if i do

Item.newmeth # it returns :oldmeth

– this is neat behavior, and it works great.  
but i was hoping to find out how to change the instance method’s  
aliases; if possible. ie

(  
@item.instance\_methods # method1  
basically, i can do:  
@item.method1 # returns whatever  
)

and i want to rename/alias method1 to method\_one, so that eventually i  
will be able to do

@item.method\_one # returns @item.method1

…is there any kind of command to change the instance\_methods’ aliases?  
something like

alias\_instance\_method :method\_one :method1  
thx

s

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [November 27, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/aliases-in-ror-for-an-instance/121366/2 "2007-11-27T13:34:17Z")

</div>

Shai :

> and i want to rename/alias method1 to method\_one, so that  
> eventually i will be able to do
> 
> @item.method\_one # returns @item.method1
> 
> …is there any kind of command to change the instance\_methods’  
> aliases? something like
> 
> alias\_instance\_method :method\_one :method1

You can use the class singleton of @item object :

class \<\< @item  
alias :method\_one :method1  
end

then you can do @item.method\_one

– Jean-François.

---

<div class="post-metadata">

**Author:** ![harper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@harper](https://www.ruby-forum.com/u/harper)\
**Post date:** [November 28, 2007, 2:04pm UTC](https://www.ruby-forum.com/t/aliases-in-ror-for-an-instance/121366/3 "2007-11-28T14:04:40Z")

</div>

> class \<\< @item  
> alias :method\_one :method1  
> end
> 
> then you can do @item.method\_one
> 
> – Jean-Franï¿½ois.

mmm … thanks 🙂 didn’t realize this was possible. where do i put this?  
in the model item.rb file? or … ?

… i managed to get around the problem, arguably ugly i must admit, by  
doing

class Item

def method\_one  
method1  
end

end

#now i can do @item.method\_one and it returns method1

thanks for the advice though  
🙂
