--1926193751-842377821-11931502650997
Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-842377821-1193150265=:30997"

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--1926193751-842377821-11931502650997
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

On Tue, 23 Oct 2007, Jes Gabriel y Gal wrote:

> On 10/23/07, David A. Black <dblack / rubypal.com> wrote:
>> On Tue, 23 Oct 2007, Jes Gabriel y Gal 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

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

-- 
Upcoming training by David A. Black/Ruby Power and Light, LLC:
   * Advancing With Rails, Edison, NJ, November 6-9
   * Advancing With Rails, Berlin, Germany, November 19-22
   * Intro to Rails, London, UK, December 3-6 (by Skills Matter)
See http://www.rubypal.com for details!
--1926193751-842377821-11931502650997--
--1926193751-842377821-11931502650997--