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#hexdump

() -> ::String
hexdump([offset, [length, [width]]]) → string or nil

Returns a human-readable string representation of the buffer. The exact format is subject to change.

Returns nil if the buffer does not reference any memory, that is, if null? returns true (for example after free or transfer).

Example
buffer = IO::Buffer.for("Hello World")
puts buffer.hexdump
# 0x00000000  48 65 6c 6c 6f 20 57 6f 72 6c 64                Hello World

As buffers are usually fairly big, you may want to limit the output by specifying the offset and length:

Example
puts buffer.hexdump(6, 5)
# 0x00000006  57 6f 72 6c 64                                  World
See also #get_values #inspect #get_value #locked also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1