Module: When::Parts::SnapShot

Defined in:
lib/when_exe/parts/method_cash.rb

Overview

デバッグのためのオブジェクト内部記録用

Constant Summary collapse

@@depth =
2

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._default(depth = 2) ⇒ Object



160
161
162
# File 'lib/when_exe/parts/method_cash.rb', line 160

def _default(depth=2)
  @@depth = depth
end

._snapshot(object, depth = @@depth, processed = {}) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/when_exe/parts/method_cash.rb', line 164

def _snapshot(object, depth=@@depth, processed={})
  obj = object.dup rescue (return object)
# def obj.is_snapshoted? ; true ; end
  if (depth==0 || processed.key?(object))
    return object if object.instance_of?(String)
    string = object.to_s
    string = "<##{object.class}>" + string unless (string =~ /^#</)
    return string
  else
    object.instance_variables.each do |v|
      if ((v =~ /^@_/) && object.kind_of?(SnapShot))
        obj._remove_instance_variable(v)
      else
        src = object.instance_variable_get(v)
        case src
        when Array
          val = src.map {|e| _snapshot(e, depth-1, processed)}
        when Hash
          val = {}
          src.each_pair {|k,c| val[_snapshot(k, depth-1, processed)] = _snapshot(c, depth-1, processed)}
        else
          val = _snapshot(src, depth-1, processed)
        end
        obj.instance_variable_set(v, val)
      end
    end
    processed[object] = true
  end
  return obj
end

Instance Method Details

#_snapshot(depth = @@depth, processed = {}) ⇒ Object



196
197
198
# File 'lib/when_exe/parts/method_cash.rb', line 196

def _snapshot(depth=@@depth, processed={})
  SnapShot._snapshot(self, depth, processed)
end