Aliases in ROR (for an instance)

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

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.

class << @item
alias :method_one :method1
end

then you can do @item.method_one

– Jean-Fran�ois.

mmm … thanks :slight_smile: 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
:slight_smile: