class BSON::Symbol::Raw
Public Class Methods
@param [ String
| Symbol
] str_or_sym The symbol represented by this
object. Can be specified as a Symbol or a String.
@see bsonspec.org/#/specification
# File lib/bson/symbol.rb, line 111 def initialize(str_or_sym) unless str_or_sym.is_a?(String) || str_or_sym.is_a?(Symbol) raise ArgumentError, "BSON::Symbol::Raw must be given a symbol or a string, not #{str_or_sym}" end @symbol = str_or_sym.to_sym end
Public Instance Methods
Check equality of the raw bson symbol against another.
@param [ Object
] other The object to check against.
@return [ true, false ] If the objects are equal.
# File lib/bson/symbol.rb, line 138 def ==(other) return false unless other.is_a?(Raw) to_sym == other.to_sym end
Converts this object to a representation directly serializable to Extended JSON
(github.com/mongodb/specifications/blob/master/source/extended-json.rst).
This method returns the integer value if relaxed representation is requested, otherwise a $numberLong hash.
@option options [ true | false ] :relaxed Whether to produce relaxed
extended JSON representation.
@return [ Hash
| Integer
] The extended json representation.
# File lib/bson/symbol.rb, line 169 def as_extended_json(**options) {'$symbol' => to_s} end
# File lib/bson/symbol.rb, line 155 def bson_type Symbol::BSON_TYPE end
Get the symbol as encoded BSON
.
@raise [ EncodingError ] If the symbol is not UTF-8.
@return [ BSON::ByteBuffer
] The buffer with the encoded object.
@see bsonspec.org/#/specification
# File lib/bson/symbol.rb, line 151 def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) buffer.put_string(to_s) end
Get the underlying symbol as a Ruby string.
@return [ String
] The symbol as a string.
# File lib/bson/symbol.rb, line 129 def to_s @symbol.to_s end