Method: String#to_hex

Defined in:
lib/pentex/core.rb

#to_hex(style = :plain) ⇒ Object

converts string to hex format
style: let’s you choose between different formats

:plain (default)   -> "61624358"
:c  (c++ style)  -> "\\x61\\x62\\x43\\x58"
:r  (ruby style) -> "\\x61\\x62\\x43\\x58"


Example:

>> "abCX".to_hex :c
=> "\\x61\\x62\\x43\\x58"


90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/pentex/core.rb', line 90

def to_hex( style = :plain )
   x = self.unpack("H*")[0]
 h = case style.to_s
   when /plain/i
   x
   when /^c/i
   x.gsub(/(..)/,'\x\1')
   when /^r/i
   x.gsub(/(..)/,'\x\1')
 end
 h
end