On 10/24/07, Jesù¸ Gabriel y GaláÏ <jgabrielygalan / gmail.com> wrote: > class Queue > def initialize > @buffer = [] > end > > def enqueue(element) > @buffer.unshift(element) > end > > def dequeue > @buffer.pop > end > > def empty? > @buffer.empty? > end > end > > But, there's already a Queue implementation in ruby core, so I would > use that, although that class is aimed at synchronizing threads so I > might implement a simple queue like the above at some point if I need > simple queue semantics. > I would corresponding class for Stack, with push/pop being delegated > to array's push and pop :-). Or just use an array if the fact of > having more methods than a stack is not a problem :-). > > Jesus. You want to -- as mentioned elsewhere in this thread -- push it in the front and take it out the back. Interesting. I guess it all comes down to what direction you want to go. I like to see the procession moving towards the zeroth position and not to some indexth position. If I was going to queue, it would be more like... class Queue def initialize enum @list = enum if enum.is_a? Enumerable end def enqueue object @list << object #haven't looked at C code, but #I think this is the same as #push end def dequeue @list.shift end def cut_in_line object @list.unshift object end def bouncer_removes_last_guy @list.pop end end Todd