#1272 new
Lars Gierth

Dictionary#keys should return a #dup

Reported by Lars Gierth | May 17th, 2010 @ 08:44 PM


currently, modifying a Dictionary while iterating over its keys doesn't work.

dict = Dictionary.new
dict[:foo] = "asd"
dict[:bar] = "fgh"
dict[:t1] = 123
dict[:t2] = 456
dict.each do |k|
  do_sth(:with => k)

This swallows each second element, as the Enumerator contains the exact array we are modifying in dict.delete.

My suggestion is to make #delete return order.dup instead of order, patch is at http://github.com/lgierth/extlib/tree/dictionary-keys

Best regards,

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket