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)
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
|