module BSON::Symbol
Injects behaviour for encoding and decoding symbol values to and from raw bytes as specified by the BSON
spec.
@note Symbols are deprecated in the BSON
spec, but they are still
currently supported here for backwards compatibility.
@see bsonspec.org/#/specification
@since 2.0.0
Constants
- BSON_TYPE
-
A symbol is type 0x0E in the
BSON
spec.@since 2.0.0
Public Instance Methods
Source
# File lib/bson/symbol.rb, line 95 def as_extended_json(**_options) { "$symbol" => to_s } end
Converts this object to a representation directly serializable to Extended JSON
(github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
@return [ Hash
] The extended json representation.
Source
# File lib/bson/symbol.rb, line 47 def bson_type String::BSON_TYPE end
Symbols are serialized as strings as symbols are now removed from the BSON
specification. Therefore the bson_type
when serializing must be a string.
@example Get the BSON
type for the symbol.
:test.bson_type
@return [ String
] The single byte BSON
type.
@see bsonspec.org/#/specification
@since 4.0.0
Source
# File lib/bson/symbol.rb, line 61 def to_bson(buffer = ByteBuffer.new) buffer.put_symbol(self) end
Get the symbol as encoded BSON
.
@example Get the symbol as encoded BSON
.
:test.to_bson
@return [ BSON::ByteBuffer
] The buffer with the encoded object.
@see bsonspec.org/#/specification
@since 2.0.0
Source
# File lib/bson/symbol.rb, line 75 def to_bson_key self end
Get the symbol as a BSON
key name encoded C symbol.
@example Get the symbol as a key name.
:test.to_bson_key
@return [ String
] The encoded symbol as a BSON
key.
@see bsonspec.org/#/specification
@since 2.0.0