Skip to content

Commit 3eef104

Browse files
committed
DOCSP-44433: Compare BSON::Binary objects (#142)
(cherry picked from commit 4764d94)
1 parent d2cc65e commit 3eef104

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

source/tutorials/bson.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ specific to the specification:
232232
``BSON::Binary``
233233
----------------
234234

235-
Use ``BSON::Binary`` objects to store arbitrary binary data. The ``Binary``
236-
objects can be constructed from binary strings as follows:
235+
Use ``BSON::Binary`` objects to store arbitrary binary data. You can construct
236+
``Binary`` objects from binary strings, as shown in the following code:
237237

238238
.. code-block:: ruby
239239

240240
BSON::Binary.new("binary_string")
241241
# => <BSON::Binary:0x47113101192900 type=generic data=0x62696e6172795f73...>
242242

243243
By default, ``Binary`` objects are created with BSON binary subtype 0
244-
(``:generic``). The subtype can be explicitly specified to indicate that
244+
(``:generic``). You can explicitly specify the subtype to indicate that
245245
the bytes encode a particular type of data:
246246

247247
.. code-block:: ruby
@@ -252,8 +252,8 @@ the bytes encode a particular type of data:
252252
Valid subtypes are ``:generic``, ``:function``, ``:old``, ``:uuid_old``,
253253
``:uuid``, ``:md5`` and ``:user``.
254254

255-
The data and the subtype can be retrieved from ``Binary`` instances using
256-
``data`` and ``type`` attributes, as follows:
255+
You can use the ``data`` and ``type`` attributes to retrieve a
256+
``Binary`` object's data and the subtype, as shown in the following code:
257257

258258
.. code-block:: ruby
259259

@@ -263,6 +263,10 @@ The data and the subtype can be retrieved from ``Binary`` instances using
263263
binary.type
264264
=> :user
265265

266+
You can compare ``Binary`` objects by using the ``<=>`` operator, which allows
267+
you to sort objects that have the same binary subtype. To compare ``Binary`` objects,
268+
ensure that you install v5.0.2 or later of the BSON library.
269+
266270
.. note::
267271

268272
``BSON::Binary`` objects always store the data in ``BINARY`` encoding,

0 commit comments

Comments
 (0)