Class: BSON::Symbol::Raw
Overview
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Check equality of the raw bson symbol against another.
-
#as_extended_json(**_options) ⇒ Hash
Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
-
#as_json(*args) ⇒ String
Return a string representation of the raw symbol for use in application-level JSON serialization.
- #bson_type ⇒ Object
-
#initialize(str_or_sym) ⇒ Raw
constructor
Create a BSON Symbol.
-
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the symbol as encoded BSON.
-
#to_s ⇒ String
Get the underlying symbol as a Ruby string.
-
#to_sym ⇒ Symbol
Get the underlying symbol as a Ruby symbol.
Methods included from JSON
Constructor Details
#initialize(str_or_sym) ⇒ Raw
Create a BSON Symbol
108 109 110 111 112 113 114 |
# File 'lib/bson/symbol.rb', line 108 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 |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Check equality of the raw bson symbol against another.
135 136 137 138 |
# File 'lib/bson/symbol.rb', line 135 def ==(other) return false unless other.is_a?(Raw) to_sym == other.to_sym end |
#as_extended_json(**_options) ⇒ Hash
Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
172 173 174 |
# File 'lib/bson/symbol.rb', line 172 def as_extended_json(**) { '$symbol' => to_s } end |
#as_json(*args) ⇒ String
Return a string representation of the raw symbol for use in application-level JSON serialization. This method is intentionally different from #as_extended_json.
164 165 166 |
# File 'lib/bson/symbol.rb', line 164 def as_json(*args) to_s end |
#bson_type ⇒ Object
152 153 154 |
# File 'lib/bson/symbol.rb', line 152 def bson_type Symbol::BSON_TYPE end |
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the symbol as encoded BSON.
148 149 150 |
# File 'lib/bson/symbol.rb', line 148 def to_bson(buffer = ByteBuffer.new) buffer.put_string(to_s) end |
#to_s ⇒ String
Get the underlying symbol as a Ruby string.
126 127 128 |
# File 'lib/bson/symbol.rb', line 126 def to_s @symbol.to_s end |
#to_sym ⇒ Symbol
Get the underlying symbol as a Ruby symbol.
119 120 121 |
# File 'lib/bson/symbol.rb', line 119 def to_sym @symbol end |