In Files

Namespace

Methods

Included Modules

BSON::Hash

Injects behaviour for encoding and decoding hashes to and from raw bytes as specified by the BSON spec.

@see bsonspec.org/#/specification

@since 2.0.0

Constants

BSON_TYPE

An hash (embedded document) is type 0x03 in the BSON spec.

@since 2.0.0

Public Instance Methods

to_bson(encoded = ''.force_encoding(BINARY)) click to toggle source

Get the hash as encoded BSON.

@example Get the hash as encoded BSON.

{ "field" => "value" }.to_bson

@return [ String ] The encoded string.

@see bsonspec.org/#/specification

@since 2.0.0

# File lib/bson/hash.rb, line 41
def to_bson(encoded = ''.force_encoding(BINARY))
  encode_with_placeholder_and_null(BSON_ADJUST, encoded) do |encoded|
    each do |field, value|
      encoded << value.bson_type
      field.to_bson_key(encoded)
      value.to_bson(encoded)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.