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-b9f4589650daunstable
parent
23d0c7d7d0
commit
6bdf2a4e2b
|
@ -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
|
||||
|
||||
#
|
||||
|
|
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
#
|
||||
|
@ -138,4 +150,4 @@ protected
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue