lib/ronin/formatting/extensions/text/array.rb in ronin-support-0.2.0 vs lib/ronin/formatting/extensions/text/array.rb in ronin-support-0.3.0

- old
+ new

@@ -35,19 +35,21 @@ # # => [0x41, 0x42, 0x42, 0x90] # # @api public # def bytes - self.inject([]) do |accum,elem| - if elem.kind_of?(Integer) - accum << elem + bytes = [] + + each do |element| + if element.kind_of?(Integer) + bytes << element else - elem.to_s.each_byte { |b| accum << b } + element.to_s.each_byte { |b| bytes << b } end - - accum end + + return bytes end # # Decodes the characters contained within the Array. The Array may contain # either Integer or String objects. @@ -60,11 +62,11 @@ # # => ["A", "A", " "] # # @api public # def chars - array_bytes = self.bytes + array_bytes = bytes array_bytes.map! { |b| b.chr } return array_bytes end @@ -98,11 +100,11 @@ # # => ['\x41', '\x42', '\x42', '\x90'] # # @api public # def hex_chars - array_bytes = self.bytes + array_bytes = bytes array_bytes.map! { |b| '\x%x' % b } return array_bytes end @@ -122,10 +124,10 @@ # # => ['0x41', '0x42', '0x42', '0x90'] # # @api public # def hex_integers - array_bytes = self.bytes + array_bytes = bytes array_bytes.map! { |b| '0x%x' % b } return array_bytes end