Only convert direct hash instances in hash with indifferent access.
This commit is contained in:
parent
9332cc582e
commit
ce9456eca0
@ -140,11 +140,10 @@ def convert_key(key)
|
||||
end
|
||||
|
||||
def convert_value(value)
|
||||
case value
|
||||
when Hash
|
||||
if value.class == Hash
|
||||
self.class.new_from_hash_copying_default(value)
|
||||
when Array
|
||||
value.dup.replace(value.collect { |e| e.is_a?(Hash) ? self.class.new_from_hash_copying_default(e) : e })
|
||||
elsif value.is_a?(Array)
|
||||
value.dup.replace(value.map { |e| convert_value(e) })
|
||||
else
|
||||
value
|
||||
end
|
||||
|
@ -12,6 +12,9 @@ class IndifferentHash < HashWithIndifferentAccess
|
||||
class SubclassingArray < Array
|
||||
end
|
||||
|
||||
class SubclassingHash < Hash
|
||||
end
|
||||
|
||||
def setup
|
||||
@strings = { 'a' => 1, 'b' => 2 }
|
||||
@symbols = { :a => 1, :b => 2 }
|
||||
@ -105,6 +108,11 @@ def test_stringify_keys_bang_for_hash_with_indifferent_access
|
||||
assert_equal @strings, @mixed.with_indifferent_access.dup.stringify_keys!
|
||||
end
|
||||
|
||||
def test_hash_subclass
|
||||
flash = { "foo" => SubclassingHash.new.tap { |h| h["bar"] = "baz" } }.with_indifferent_access
|
||||
assert_kind_of SubclassingHash, flash["foo"]
|
||||
end
|
||||
|
||||
def test_indifferent_assorted
|
||||
@strings = @strings.with_indifferent_access
|
||||
@symbols = @symbols.with_indifferent_access
|
||||
|
Loading…
Reference in New Issue
Block a user