From: Harry Kakueki Date: 2007-05-14T23:02:29+09:00 Subject: Re: Hash#shift On 5/14/07, Robert Klemme wrote: > I never had use for this myself but it might be useful in cases where > you want to iterate through a (possibly temporary) Hash and make sure > that elements that you have processed are removed. Like > > >> h={:foo=>1, :bar=>2, :baz=>3} > => {:baz=>3, :foo=>1, :bar=>2} > >> until h.empty? > >> k, v = h.shift > >> puts "processing: #{k} - #{v}" > >> end > processing: baz - 3 > processing: foo - 1 > processing: bar - 2 > => nil > >> h > => {} > > If you now leave the loop early (for whatever reasons, "return" or > raise) you only leave elements that still have to be processed in the Hash. > > Kind regards > > robert > > OK. You would be shifting in a somewhat random order but you would be able to keep track of what had not yet been shifted. Thanks for that example. Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/