Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created January 19, 2009 21:51
Show Gist options
  • Save ashgti/49196 to your computer and use it in GitHub Desktop.
Save ashgti/49196 to your computer and use it in GitHub Desktop.
#!ruby1.9
counts = []
reference = []
file = File.new(__FILE__)
line_count = 1
while line = file.gets
reference[line_count] = line
line_count += 1
end
set_trace_func proc { |event, file, line, id, binding, classname|
if file == __FILE__
if counts[line]
counts[line] += 1
else
counts[line] = 1
end
end
}
class Test
def test
a = 1
b = 2
if a == 5
b += 5
else
b += 1
end
b
end
end
t = Test.new
t.test
a, b, c = (1..3).to_a
10.times do
a += 1
20.times do |i|
b += i
b.times do
c += (j = (b-a).abs) > 0 ? j : 0
end
end
end
puts "a: #{a}"
puts "b: #{b}"
puts "c: #{c}"
set_trace_func nil
for k in 20..(__LINE__ - 2)
puts "#{counts[k]} #{reference[k]}"
end
a: 11
b: 1902
c: 229330293
 
 
5 class Test
4   def test
1     a = 1
1     b = 2
4     if a == 5
       b += 5
     else
3       b += 1
     end
2     b
   end
 end
 
5 t = Test.new
1 t.test
 
6 a, b, c = (1..3).to_a
3 10.times do
30   a += 1
30   20.times do |i|
600     b += i
600     b.times do
2216400       c += (j = (b-a).abs) > 0 ? j : 0
     end
   end
 end
 
9 puts "a: #{a}"
9 puts "b: #{b}"
9 puts "c: #{c}"
 
2 set_trace_func nil
a: 11
b: 1902
c: 229330293
 
 
3 class Test
5   def test
1     a = 1
1     b = 2
1     if a == 5
       b += 5
     else
1       b += 1
     end
1     b
   end
2 end
 
3 class Another
1   if true
    end
2   end
 
6 a, b, c = (1..3).to_a
3 10.times do
10   a += 1
30   20.times do |i|
200     b += i
600     b.times do
923500       c += (j = (b-a).abs) > 0 ? j : 0
     end
   end
 end
 
11 puts "a: #{a}"
11 puts "b: #{b}"
11 puts "c: #{c}"
 
2 set_trace_func nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment