It interprets the string as hexadecimal numbers, two characters per byte, and converts it into a string with characters with the corresponding ASCII code:
["464F4F"].pack('H*')
For the opposite conversion, use unpack :
'FOO'.unpack('H*')
This is a bit more complicated for encodings without ASCII-8BIT:
"รก".encoding # => #<Encoding:UTF-8> "รก".unpack('H*') # => ["c3a1"] ['c3a1'].pack('H*') # => "\xC3\xA1" ['c3a1'].pack('H*').encoding # => #<Encoding:ASCII-8BIT> ['c3a1'].pack('H*').force_encoding('UTF-8') # => "รก"
undur_gongor
source share