From: Nat Pryce Date: 2002-11-26T22:13:27+09:00 Subject: Re: RCR: Stack, Queue alias methods in Array On Tue, 2002-11-26 at 09:46, Martin DeMello wrote: > Rationale: Ruby arrays can be easily used as stacks and queues, but it's > distracting to have to stop and think about which end of the array > you're working with. > > Proposed aliases: > > top <- last > enqueue, append <- push > dequeue <- shift > head <- [0] > tail <- last How about defining these in modules, so that they can be included into individual arrays or into the entire array class if needed. E.g. require 'arrayqueue' require 'arraystack' my_queue = [1,2,3] my_queue.extend ArrayQueue my_stack = [-1,-2,-3] my_stack.extend ArrayStack my_stack.push( my_queue.dequeue ) my_queue.enqueue( my_stack.pop ) Where arraystack.rb would contain: module ArrayStack def push( value ) ... end def pop ... end def top ... end end Etc. -- Nat Pryce B13media