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

127.chr.force_encoding(BINARY).freeze
GREATER =

Constant for always evaluating greater in a comparison.

Since:

  • 2.0.0

1.freeze

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:

  • The (Object)

    object to compare against.

Returns:

Since:

  • 2.0.0



49
50
51
# File 'lib/bson/max_key.rb', line 49

def <=>(other)
  GREATER
end

#as_json(*args) ⇒ Hash

Get the max key as JSON hash data.

Examples:

Get the max key as a JSON hash.

max_key.as_json

Returns:

  • (Hash)

    The max key as a JSON hash.

Since:

  • 2.0.0



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

def as_json(*args)
  { "$maxKey" => 1 }
end