Module: BSON::Symbol

Defined in:
lib/bson/symbol.rb

Overview

Note:

Symbols are deprecated in the BSON spec, but they are still currently supported here for backwards compatibility.

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

See Also:

Since:

  • 2.0.0

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BSON_TYPE =

A symbol is type 0x0E in the BSON spec.

Since:

  • 2.0.0

14.chr.force_encoding(BINARY).freeze

Instance Method Summary collapse

Instance Method Details

#to_bson(encoded = ''.force_encoding(BINARY)) ⇒ Symbol

Get the symbol as encoded BSON.

Examples:

Get the symbol as encoded BSON.

:test.to_bson

Returns:

  • (Symbol)

    The encoded symbol.

See Also:

Since:

  • 2.0.0



43
44
45
# File 'lib/bson/symbol.rb', line 43

def to_bson(encoded = ''.force_encoding(BINARY))
  to_s.to_bson(encoded)
end

#to_bson_key(encoded = ''.force_encoding(BINARY)) ⇒ String

Get the symbol as a BSON key name encoded C symbol.

Examples:

Get the symbol as a key name.

:test.to_bson_key

Returns:

  • (String)

    The encoded symbol as a BSON key.

See Also:

Since:

  • 2.0.0



57
58
59
# File 'lib/bson/symbol.rb', line 57

def to_bson_key(encoded = ''.force_encoding(BINARY))
  to_s.to_bson_key(encoded)
end