If you deal with a lot of binary data in Ruby, you'll want this snippet of code to add a String#hex_inspect
method, because String#inspect
makes it hard to see the actual bytes. Example usage:
binary_string = "\x0d\x0e\x00\x40"
binary_string.hex_inspect # => "\x0d\x0e\x00\x40" (good)
binary_string.inspect # => "\r\x0E\x00@" (bad)