Project

General

Profile

Bug #11088 ยป bug_hunt_simple.rb

austin (Austin Ziegler), 05/10/2015 02:31 AM

 
1
module SimpleInspect
2
  def inspect
3
    result = if inspected?
4
               "#<%s (%d) ...>" % [ inspected_key, inspected_count ]
5
             else
6
               super
7
             end
8
    inspect!
9
    "\n" + result
10
  end
11

    
12
  private
13
  def inspected?
14
    inspected[inspected_key].nonzero?
15
  end
16

    
17
  def inspect!
18
    inspected[inspected_key] += 1
19
  end
20

    
21
  def inspected_count
22
    inspected[inspected_key]
23
  end
24

    
25
  def inspected
26
    $__inspected__ ||= Hash.new { |h, k| h[k] = 0 }
27
  end
28

    
29
  def inspected_key
30
    "%s:0x%014x" % [ self.class, "0x%014x" % (object_id * 2) ]
31
  end
32
end
33

    
34
class Object
35
  include SimpleInspect
36
end
37

    
38
class Entity
39
end
40
class Indect
41
end
42
class Koppler
43
end
44
class Occupancy
45
end
46
class Control
47
end
48
class ScheduleEntry
49
end
50
class SQLiteStorage
51
end
52
class UBox
53
end
54
class USpot
55
end
56
class UFlag
57
end
58
class UFlow
59
end
60
class Sign
61
end
62
class CounterGroup
63
end
64

    
65
read = File.read "ruby_object.dump"
66

    
67
File.open('simple-inspect.txt', 'w') { |f| f.puts Marshal.load(read).inspect }
68
File.open('simple-inspect-stats.txt', 'w') { |f| f.puts $__inspected__.inspect }
69

    
70
Marshal.load(read).each do |id, el|
71
  puts el.id
72
  p el
73
end