I have a string containing hex code values of ASCII characters, e.g. "666f6f626172"
. I want to convert it to the corresponding string ("foobar"
).
This is working but ugly:
"666f6f626172".scan(/../).map(&:hex).map(&:chr).join # => "foobar"
Is there a better (more concise) way? Could unpack
be helpful somehow?