Object
Represents a code type, which is a wrapper around javascript code.
@see bsonspec.org/#/specification
@since 2.0.0
Deserialize code from BSON.
@param [ BSON ] bson The encoded code.
@return [ TrueClass, FalseClass ] The decoded code.
@see bsonspec.org/#/specification
@since 2.0.0
# File lib/bson/code.rb, line 100 def self.from_bson(bson) new(bson.read(Int32.from_bson(bson)).from_bson_string.chop!) end
Instantiate the new code.
@example Instantiate the new code.
BSON::Code.new("this.value = 5")
@param [ String ] javascript The javascript code.
@since 2.0.0
# File lib/bson/code.rb, line 71 def initialize(javascript = "") @javascript = javascript end
Determine if this code object is equal to another object.
@example Check the code equality.
code == other
@param [ Object ] other The object to compare against.
@return [ true, false ] If the objects are equal.
@since 2.0.0
# File lib/bson/code.rb, line 46 def ==(other) return false unless other.is_a?(Code) javascript == other.javascript end
Encode the javascript code.
@example Encode the code.
code.to_bson
@return [ String ] The encoded string.
@see bsonspec.org/#/specification
@since 2.0.0
# File lib/bson/code.rb, line 85 def to_bson(encoded = ''.force_encoding(BINARY)) encode_with_placeholder_and_null(STRING_ADJUST, encoded) do |encoded| javascript.to_bson_string(encoded) end end
Generated with the Darkfish Rdoc Generator 2.