From: Logan Capaldo Date: 2007-06-26T00:13:02+09:00 Subject: Re: alias and subclasses ------=_Part_104133_17104586.1182784383743 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/24/07, Tim Clark wrote: > > Hi everyone, > > The quick version: > Is there a Ruby-ian way to get the alias method to propagate through > subclasses? > > The longer one: > I've got two classes with some simple inheritance: > > class Ticket > def unreserve > ... > end > alias unhold unreserve > end > > class FamilyTicket < Ticket > def unreserve > ... > end > end > > FamilyTicket adds a bit of functionality to Ticket, and are reserved > in different ways, so it's unreserve method overwrites its parent > class. I would still like to use the aliased method name - e.g. > ft = FamilyTicket.new > ft.unhold > > However, the alias refers to Ticket#unreserve, not > FamilyTicket#unreserve. From the docs I understand that this is by > design, so my question is, is there a more Ruby-like way of doing the > following? > class Ticket > def unreserve > ... > end > > def unhold > unreserve > end > end Of course now you have the problem of if the sublass decides to override unhold instead of unreserve. The real solution to this problem IMO is to not start aliasing things in the first place. A given method should have one name. (I know Ruby does it with map/collect etc., but that doesn't mean I have to agree does it? :) ) Cheers, > Tim Clark > > ------=_Part_104133_17104586.1182784383743--