Class: Array
Overview
Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
This file is part of Ronin Support.
Ronin Support is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Ronin Support is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with Ronin Support. If not, see http://www.gnu.org/licenses/.
Instance Method Summary collapse
-
#bytes ⇒ Array
Decodes the bytes contained within the Array.
-
#char_string ⇒ String
The String created from the characters within the Array.
-
#chars ⇒ Array
Decodes the characters contained within the Array.
-
#hex_chars ⇒ Array<String>
Decodes the bytes contained with the Array, and escapes them as hexadecimal characters.
-
#hex_integers ⇒ Array<String>
Decodes the bytes contained with the Array, and escapes them as hexadecimal integers.
Instance Method Details
#bytes ⇒ Array
Decodes the bytes contained within the Array. The Array may contain both Integer and String objects.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ronin/formatting/extensions/text/array.rb', line 39 def bytes bytes = [] each do |element| if element.kind_of?(Integer) bytes << element else element.to_s.each_byte { |b| bytes << b } end end return bytes end |
#char_string ⇒ String
Returns The String created from the characters within the Array.
83 84 85 |
# File 'lib/ronin/formatting/extensions/text/array.rb', line 83 def char_string chars.join end |
#chars ⇒ Array
Decodes the characters contained within the Array. The Array may contain either Integer or String objects.
66 67 68 69 70 71 |
# File 'lib/ronin/formatting/extensions/text/array.rb', line 66 def chars array_bytes = bytes array_bytes.map! { |b| b.chr } return array_bytes end |
#hex_chars ⇒ Array<String>
Decodes the bytes contained with the Array, and escapes them as hexadecimal characters.
104 105 106 107 108 109 |
# File 'lib/ronin/formatting/extensions/text/array.rb', line 104 def hex_chars array_bytes = bytes array_bytes.map! { |b| '\x%x' % b } return array_bytes end |
#hex_integers ⇒ Array<String>
Decodes the bytes contained with the Array, and escapes them as hexadecimal integers.
128 129 130 131 132 133 |
# File 'lib/ronin/formatting/extensions/text/array.rb', line 128 def hex_integers array_bytes = bytes array_bytes.map! { |b| '0x%x' % b } return array_bytes end |