Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/nxt/patches/string.rb
Instance Method Summary collapse
- #from_hex_str ⇒ Object
- #from_hex_str_two ⇒ Object
-
#to_hex_str ⇒ Object
Convert the given string to a hexadecimal representation of the same data.
Instance Method Details
#from_hex_str ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nxt/patches/string.rb', line 19 def from_hex_str data = self.split(' ') str = '' data.each do |h| str += '%c' % h end str end |
#from_hex_str_two ⇒ Object
12 13 14 15 16 17 |
# File 'lib/nxt/patches/string.rb', line 12 def from_hex_str_two data = self.split(' ') str = '' data.each {|h| eval "str += '%c' % #{h}"} str 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.
5 6 7 8 9 |
# File 'lib/nxt/patches/string.rb', line 5 def to_hex_str str = '' self.each_byte {|b| str << '0x%02x ' % b} str end |