Ruby Hexdump method for Class String



This is a small extension for the Ruby class String, which provides a hexdump method to display string contents as a hexdump..

It takes one optional boolean parameter, to determine if you want to print series of zeros, or if you want to colapse them.



	# irb
	irb(main):001:0>  require 'hexdump'
	=> true
	
	irb(main):002:0> s = "some random string" << "\0"*46 << "some more stuff"
	=> "some random string\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000some more stuff"

        irb(main):003:0> s.hexdump

	 index       0 1 2 3  4 5 6 7  8 9 A B  C D E F

	00000000    736f6d65 2072616e 646f6d20 73747269    some random stri
	00000010    6e670000 00000000 00000000 00000000    ng..............
	00000020    00000000 00000000 00000000 00000000    ................
	00000030    00000000 00000000 00000000 00000000    ................
	00000040    736f6d65 206d6f72 65207374 756666      some more stuff
	=> nil

	irb(main):004:0> s.hexdump(true)

	 index       0 1 2 3  4 5 6 7  8 9 A B  C D E F

	00000000    736f6d65 2072616e 646f6d20 73747269    some random stri
	00000010    6e670000 00000000 00000000 00000000    ng..............
	  ....      00 .. 00 00 .. 00 00 .. 00 00 .. 00    ................
	00000040    736f6d65 206d6f72 65207374 756666      some more stuff
	=> nil

	

Download

 

License

Freely available under the terms of the OpenSource "Artistic License" in combination with the Addendum A (below)
In case you did not get a copy of the license along with the software, it is also available at:   http://www.unixgods.org/~tilo/artistic-license.html