Class: BSON::MaxKey

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

Overview

Represents a $maxKey type, which compares less than any other value in the specification.

See Also:

Since:

  • 2.0.0

Constant Summary collapse

BSON_TYPE =

A $maxKey is type 0x7F in the BSON spec.

Since:

  • 2.0.0

::String.new(127.chr, encoding: BINARY).freeze
GREATER =

Constant for always evaluating greater in a comparison.

Since:

  • 2.0.0

1

Instance Method Summary collapse

Methods included from Specialized

#==, #to_bson

Methods included from JSON

#to_json

Instance Method Details

#<=>(other) ⇒ Integer

When comparing a max key with any other object, the max key will always be greater.

Examples:

Compare with another object.

max_key <=> 1000

Parameters:

  • other (Object)

    The object to compare against.

Returns:

Since:

  • 2.0.0



51
52
53
# File 'lib/bson/max_key.rb', line 51

def <=>(other)
  GREATER
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



72
73
74
# File 'lib/bson/max_key.rb', line 72

def as_extended_json(**options)
  { "$maxKey" => 1 }
end

#as_json(*_args) ⇒ Hash

Return a representation of the object for use in application-level JSON serialization. Since BSON::MaxKey is used exclusively in BSON-related contexts, this method returns the canonical Extended JSON representation.

Returns:

  • (Hash)

    The extended json representation.

Since:

  • 2.0.0



61
62
63
# File 'lib/bson/max_key.rb', line 61

def as_json(*_args)
  as_extended_json
end