From: Brian Candler Date: 2008-11-01T06:34:21+09:00 Subject: Re: Data Structs in Ruby Bilyk, Alex wrote: > Array can act as a stack as it has #pop and #last. It can also act as a > queue as it also has #first and #shift. You can wrap this functionality > in a Queue and Stack classes to make it more explicit if you like. Included in the Ruby standard library: irb(main):001:0> require 'thread' => true irb(main):002:0> q = Queue.new => # irb(main):003:0> q.push "abc" => # irb(main):004:0> q.pop => "abc" This queue object is thread-safe. There is also SizedQueue, which blocks pushes when the queue reaches a certain size, until another element has been popped. -- Posted via http://www.ruby-forum.com/.