Class: BSON::Undefined

Inherits:
Object
  • Object
show all
Includes:
JSON, Specialized
Defined in:
lib/bson/undefined.rb

Overview

Represents the Undefined BSON type

See Also:

Since:

  • 2.0.0

Constant Summary collapse

BSON_TYPE =

Undefined is type 0x06 in the BSON spec.

Since:

  • 2.0.0

::String.new(6.chr, encoding: BINARY).freeze

Instance Method Summary collapse

Methods included from Specialized

#to_bson

Methods included from JSON

#to_json

Instance Method Details

#==(other) ⇒ true, false

Determine if undefined is equal to another object.

Examples:

Check undefined equality.

BSON::Undefined.new == object

Parameters:

  • other (Object)

    The object to check against.

Returns:

  • (true, false)

    If the objects are equal.

Since:

  • 2.0.0



43
44
45
# File 'lib/bson/undefined.rb', line 43

def ==(other)
  self.class == other.class
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.rst).

Parameters:

  • opts (Hash)

    a customizable set of options

Returns:

  • (Hash)

    The extended json representation.

Since:

  • 2.0.0



66
67
68
# File 'lib/bson/undefined.rb', line 66

def as_extended_json(**options)
  { "$undefined" => true }
end

#as_json(*args) ⇒ nil

Return a string representation of the BSON::Undefined for use in application-level JSON serialization. This method is intentionally different from #as_extended_json.

Examples:

Get the undefined as a JSON-serializable object.

undefined.as_json

Returns:

  • (nil)

    The undefined as nil.

Since:

  • 2.0.0



55
56
57
# File 'lib/bson/undefined.rb', line 55

def as_json(*args)
  nil
end