Class: Array

Ronin - A Ruby platform for exploit development and security research.

Copyright © 2006-2009 Hal Brodigan (postmodern.mod3 at gmail.com)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Public Visibility

Public Instance Method Summary

#bytes

Decodes the bytes contained within the Array.

Returns: Array

#char_string

Returns: String

#chars

Decodes the characters contained within the Array.

Returns: Array

#power_set

Calculates the power-set of the Array.

Returns: Array

Public Instance Method Details

bytes

public Array bytes

Decodes the bytes contained within the Array. The Array may contain both Integer and String objects.

Meta Tags

Examples

  [0x41, 0x41, 0x20].bytes
  # => [0x41, 0x41, 0x20]
  ['A', 'BB', 0x90].bytes
  # => [0x41, 0x42, 0x42, 0x90]

Returns:

[Array]

The bytes contained in the Array.

[View source]


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ronin/formatting/extensions/text/array.rb', line 38

def bytes
  self.inject([]) do |accum,elem|
    if elem.kind_of?(Integer)
      accum << elem
    else
      elem.to_s.each_byte { |b| accum << b }
    end

    accum
  end
end

char_string

public String char_string

Meta Tags

Example:

  [0x41, 0x41, 0x20].char_string
  # => "AA "

Returns:

[String]

The String created from the characters within the Array.

[View source]


73
74
75
# File 'lib/ronin/formatting/extensions/text/array.rb', line 73

def char_string
  chars.join
end

chars

public Array chars

Decodes the characters contained within the Array. The Array may contain either Integer or String objects.

Meta Tags

Example:

  [0x41, 0x41, 0x20].chars
  # => ["A", "A", " "]

Returns:

[Array]

The characters generated from the array.

[View source]


61
62
63
# File 'lib/ronin/formatting/extensions/text/array.rb', line 61

def chars
  self.bytes.map { |b| b.chr }
end

power_set

public Array power_set

Calculates the power-set of the Array.

Meta Tags

Example:

  [1,2,3].power_set
  # => [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]

Returns:

[Array]

The power set of the array.

[View source]


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ronin/extensions/array.rb', line 35

def power_set
  inject([[]]) do |power_set,element|
    sub_set = []

    power_set.each do |i|
      sub_set << i
      sub_set << i + [element]
    end

    sub_set
  end
end
Generated on Friday, September 25 2009 at 02:57:41 PM by YARD 0.2.3.5 (ruby-1.8.6).