Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO::Buffer#<=>

(::IO::Buffer) -> ::Integer
<=>(other) → integer

Returns a negative integer, zero, or a positive integer if the receiver is less than, equal to, or greater than other, respectively.

Buffers are compared by size first, and if the sizes are equal, by the exact contents of the memory they are referencing using memcmp. Only the sign of the returned integer is meaningful; the result of memcmp is returned as is.

Example
IO::Buffer.for("abc") <=> IO::Buffer.for("abc") # => 0
IO::Buffer.for("abc") <=> IO::Buffer.for("ab")  # => 1
IO::Buffer.for("abc") <=> IO::Buffer.for("abd") # => -1
See also #& #^ .string #| also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1