Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/nxt/patches/string.rb
Overview
Some patches that extend the default Ruby String class with some useful methods.
Instance Method Summary collapse
- #from_hex_str ⇒ Object
-
#to_hex_str ⇒ Object
Convert the given string to a hexadecimal representation of the same data.
Instance Method Details
#from_hex_str ⇒ Object
15 16 17 |
# File 'lib/nxt/patches/string.rb', line 15 def from_hex_str unpack('C*') end |
#to_hex_str ⇒ Object
Convert the given string to a hexadecimal representation of the same data. This method is non-destructive, it will return a new copy of the string convered to hex.
9 10 11 12 13 |
# File 'lib/nxt/patches/string.rb', line 9 def to_hex_str str = '' each_byte { |b| str << format('0x%02x ', b) } str end |