Class: Object

Inherits:
BasicObject
Defined in:
lib/arachni/ruby/object.rb

Overview

Overloads the Object class providing a #deep_clone method.

Author:

Instance Method Summary collapse

Instance Method Details

#deep_cloneObject

Deep-clones self using a Marshal dump-load.

Returns:

  • (Object)

    Duplicate of self.



29
30
31
32
33
34
35
# File 'lib/arachni/ruby/object.rb', line 29

def deep_clone
    begin
        Marshal.load( Marshal.dump( self ) )
    rescue => e
        self
    end
end

#realsize(invoke_size = true) ⇒ Integer

Attempts to approximate the real size of self by summing up the size of all its instance variables’ values and names.

Parameters:

  • invoke_size (Bool) (defaults to: true)

    Whether or not to include self’s ‘size` in the return value.

Returns:

  • (Integer)

    Size of self.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/arachni/ruby/object.rb', line 46

def realsize( invoke_size = true )
    return 1 if nil?

    sz = 0
    sz = size rescue 0 if invoke_size

    ivs = instance_variables
    return sz if ivs.empty?

    ivs.reduce( sz ) do |s, iv|
        v = instance_variable_get( iv )
        s += begin
            rs = v.realsize
            rs > 0 ? rs : v.size
        rescue => e
            ap e
            0
        end
        s += iv.size
    end
end