From: "Jesús Gabriel y Galán" Date: 2007-10-23T23:31:52+09:00 Subject: Re: pop/push, shift/unshift On 10/23/07, David A. Black wrote: > On Tue, 23 Oct 2007, Jesús Gabriel y Galán wrote: > > I like this: > > > > class Array > > alias :enqueue :push > > alias :dequeue :shift > > end > > > > Then you get Queue semantics and the start of the queue is the first > > element in the Array :-). (you could do enqueue --> unshift, dequeue > > --> pop if you rather have the first element of the queue the last in > > the array). > > No thanks. #shift/#unshift are fine, and certainly I don't want to > have to figure out what people have aliased enqueue and dequeue to > before I can understand their code. Fair enough, although the idea was to use such an object using just queue semantics, so everybody knows what enqueue/dequeue do. Maybe aliasing them in Array doesn't make sense: what about having those alias in a class Queue < Array or in the instance of the array you plan to use just as a queue? queue = [] class << queue alias :enqueue :push alias :dequeue :shift end Jesus.