From: Bob Hutchison Date: 2007-10-23T23:47:42+09:00 Subject: Re: pop/push, shift/unshift On 23-Oct-07, at 10:37 AM, David A. Black wrote: > On Tue, 23 Oct 2007, Jes˙s Gabriel y Gal·n wrote: > >> 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 > > Now you're talking :-) You could even wrap it up like this: > > module Queue > def self.extend_object(o) > class << o > alias enqueue push > alias dequeue shift > end > end > end > > q = [].extend(Queue) > > (I'm a big #extend fan.) > > > David > > This is potentially a troublesome implementation. I believe that the queue is going to grow and grow. See my other messages about the behaviour of un/shift. Cheers, Bob ---- Bob Hutchison -- tumblelog at http:// www.recursive.ca/so/ Recursive Design Inc. -- weblog at http://www.recursive.ca/ hutch http://www.recursive.ca/ -- works on http://www.raconteur.info/ cms-for-static-content/home/