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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 :method1You 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---