Proactively wrap each() in other Hash based classes to avoid situations that trigger modification during enumeration

git-svn-id: file:///home/svn/framework3/trunk@12479 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2011-04-30 04:59:27 +00:00
parent 23d0c7d7d0
commit 6bdf2a4e2b
6 changed files with 73 additions and 1 deletions

View File

@ -212,6 +212,18 @@ class DataStore < Hash
self
end
#
# Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+
# "can't add a new key into hash during iteration"
#
def each(&block)
list = []
self.keys.sort.each do |sidx|
list << [sidx, self[sidx]]
end
list.each(&block)
end
protected
#

View File

@ -110,6 +110,18 @@ class ModuleSet < Hash
(self[name]) ? true : false
end
#
# Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+
# "can't add a new key into hash during iteration"
#
def each(&block)
list = []
self.keys.sort.each do |sidx|
list << [sidx, self[sidx]]
end
list.each(&block)
end
#
# Enumerates each module class in the set.
#

View File

@ -632,6 +632,18 @@ class OptionContainer < Hash
each_pair(&block)
end
#
# Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+
# "can't add a new key into hash during iteration"
#
def each(&block)
list = []
self.keys.sort.each do |sidx|
list << [sidx, self[sidx]]
end
list.each(&block)
end
#
# Merges the options in this container with another option container and
# returns the sorted results.

View File

@ -177,6 +177,18 @@ class JobContainer < Hash
self.delete(inst.jid.to_s)
end
#
# Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+
# "can't add a new key into hash during iteration"
#
def each(&block)
list = []
self.keys.sort.each do |sidx|
list << [sidx, self[sidx]]
end
list.each(&block)
end
protected
attr_accessor :job_id_pool # :nodoc:

View File

@ -141,6 +141,18 @@ class Packet::Header < Hash
self.dcase_hash.clear
end
#
# Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+
# "can't add a new key into hash during iteration"
#
def each(&block)
list = []
self.keys.sort.each do |sidx|
list << [sidx, self[sidx]]
end
list.each(&block)
end
#
# The raw command string associated with the header which will vary between
# requests and responses.

View File

@ -127,6 +127,18 @@ class ServiceManager < Hash
return false
end
#
# Overrides the builtin 'each' operator to avoid the following exception on Ruby 1.9.2+
# "can't add a new key into hash during iteration"
#
def each(&block)
list = []
self.keys.sort.each do |sidx|
list << [sidx, self[sidx]]
end
list.each(&block)
end
protected
#