From: Nikolay Pavlov Date: 2007-09-08T04:03:13+09:00 Subject: Re: Singleton aliases On Friday 07 September 2007 21:19:04 Wilson Bilkovich wrote: > On 9/7/07, Nikolay Pavlov wrote: > > Hello all. > > I have a class with instance method "each" and i want to add variable > > aliases for it based on some preferences of the generated objects. > > Did some one know how i can achieve this? > This is one way. There are several. > I am assuming you mean that only that particular instance should have > this method, and not other instances of the same class. > > metaclass = class << self;self;end > sym = :some_name_you_generated > metaclass.send :alias_method, sym, :each > > More traditionally, this is usually a good place to consider using > inheritance. :) Wow. Thanks for all suggestions. But that one was really helpful and simple to me and i've come up to this implementation: def singleton_alias(alias_name, name) klass = class << self; self; end klass.send :alias_method, alias_name.to_sym, name.to_sym end -- ====================================================================== - Best regards, Nikolay Pavlov. <<<----------------------------------- ======================================================================