diff --git a/lib/bson/hash.rb b/lib/bson/hash.rb index 197349cc5..4bd7adf29 100644 --- a/lib/bson/hash.rb +++ b/lib/bson/hash.rb @@ -167,7 +167,7 @@ def maybe_dbref(hash) # # @return [ Hash ] the hash parsed from the buffer def parse_hash_from_buffer(buffer, **options) - hash = Document.allocate + hash = ruby_base_type.allocate start_position = buffer.read_position expected_byte_size = buffer.get_int32 @@ -200,6 +200,10 @@ def parse_hash_contents(hash, buffer, **options) hash.store(field, value) end end + + def ruby_base_type + BSON::Registry.get(BSON_TYPE) + end end # Register this type when the module is loaded. diff --git a/lib/bson/registry.rb b/lib/bson/registry.rb index 047df9a5b..beb25cdb8 100644 --- a/lib/bson/registry.rb +++ b/lib/bson/registry.rb @@ -42,7 +42,7 @@ module Registry # # @since 2.0.0 def get(byte, field = nil) - if type = MAPPINGS[byte] || (byte.is_a?(String) && type = MAPPINGS[byte.ord]) + if (type = MAPPINGS[byte]) || (byte.is_a?(String) && (type = MAPPINGS[byte.ord])) type else handle_unsupported_type!(byte, field)