class BSON::Code
@since 2.0.0
@see bsonspec.org/#/specification<br><br>Represents a code type, which is a wrapper around javascript code.
def self.from_bson(buffer, **options)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(TrueClass, FalseClass)
- The decoded code.
Options Hash:
(**options)
-
:mode
(nil | :bson
) -- Decoding mode to use.
Parameters:
-
buffer
(ByteBuffer
) -- The byte buffer.
def self.from_bson(buffer, **options) new(buffer.get_string) end
def ==(other)
- Since: - 2.0.0
Returns:
-
(true, false)
- If the objects are equal.
Parameters:
-
other
(Object
) -- The object to compare against.
Other tags:
- Example: Check the code equality. -
def ==(other) return false unless other.is_a?(Code) javascript == other.javascript end
def as_extended_json(**_options)
-
(Hash)
- The extended json representation.
Options Hash:
(**opts)
-
:mode
(nil | :relaxed | :legacy
) -- Serialization mode
def as_extended_json(**_options) { "$code" => javascript } end
def as_json(*_args)
-
(Hash)
- The extended json representation.
def as_json(*_args) as_extended_json end
def initialize(javascript = "")
- Since: - 2.0.0
Parameters:
-
javascript
(String
) -- The javascript code.
Other tags:
- Example: Instantiate the new code. -
def initialize(javascript = "") @javascript = javascript end
def to_bson(buffer = ByteBuffer.new)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(BSON::ByteBuffer)
- The buffer with the encoded object.
Other tags:
- Example: Encode the code. -
def to_bson(buffer = ByteBuffer.new) buffer.put_string(javascript) # @todo: was formerly to_bson_string end