Resolve 'Error: can't add a new key into hash during iteration'

This commit is contained in:
Douglas Eichelberger 2024-01-12 10:55:27 -08:00
parent fa7b8ff0df
commit 1790904152

View File

@ -102,7 +102,8 @@ class Hash
def _deep_transform_keys_in_object!(object, &block)
case object
when Hash
object.each_key do |key|
# We can't use `each_key` here because we're updating the hash in-place
object.keys.each do |key| # rubocop:disable Style/HashEachMethods
value = object.delete(key)
object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
end