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



221
222
223
# File 'lib/when_exe/parts/method_cash.rb', line 221

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

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



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/when_exe/parts/method_cash.rb', line 225

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



257
258
259
# File 'lib/when_exe/parts/method_cash.rb', line 257

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