Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/environment.rb

Instance Method Summary collapse

Instance Method Details

#from_hexObject

Convert from hex. E.g. “0d0a”.from_hex is “rn”. Raises ArgumentError on invalid input.



80
81
82
83
84
85
86
87
88
# File 'lib/environment.rb', line 80

def from_hex
    return "" if self.empty?
    hex = self
    Integer("0x#{hex}")
    if hex.length % 2 == 1
        hex = "0#{hex}"
    end
    [hex].pack 'H*'
end