Module: BSON::TrueClass

Defined in:
lib/bson/true_class.rb

Overview

Injects behaviour for encoding and decoding true values to and from raw bytes as specified by the BSON spec.

See Also:

Since:

  • 2.0.0

Constant Summary collapse

TRUE_BYTE =

A true value in the BSON spec is 0x01.

Since:

  • 2.0.0

1.chr.force_encoding(BINARY).freeze

Instance Method Summary collapse

Instance Method Details

#bson_typeString

The BSON type for true values is the general boolean type of 0x08.

Examples:

Get the bson type.

false.bson_type

Returns:

  • (String)

    The character 0x08.

Since:

  • 2.0.0



38
39
40
# File 'lib/bson/true_class.rb', line 38

def bson_type
  Boolean::BSON_TYPE
end

#to_bson(encoded = ''.force_encoding(BINARY)) ⇒ String

Get the true boolean as encoded BSON.

Examples:

Get the true boolean as encoded BSON.

true.to_bson

Returns:

  • (String)

    The encoded string.

See Also:

Since:

  • 2.0.0



52
53
54
# File 'lib/bson/true_class.rb', line 52

def to_bson(encoded = ''.force_encoding(BINARY))
  encoded << TRUE_BYTE
end