Class: Annals
- Inherits:
-
Object
- Object
- Annals
- Defined in:
- lib/annals.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#max ⇒ Object
Returns the value of attribute max.
Instance Method Summary collapse
- #capture(&block) ⇒ Object
-
#initialize(max = 20, &block) ⇒ Annals
constructor
A new instance of Annals.
- #lines ⇒ Object
- #puts ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #unshift(line) ⇒ Object
Constructor Details
#initialize(max = 20, &block) ⇒ Annals
Returns a new instance of Annals.
5 6 7 8 |
# File 'lib/annals.rb', line 5 def initialize(max = 20, &block) @max = max start end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
3 4 5 |
# File 'lib/annals.rb', line 3 def buffer @buffer end |
#max ⇒ Object
Returns the value of attribute max.
3 4 5 |
# File 'lib/annals.rb', line 3 def max @max end |
Instance Method Details
#capture(&block) ⇒ Object
10 11 12 13 14 |
# File 'lib/annals.rb', line 10 def capture(&block) start yield stop end |
#lines ⇒ Object
16 17 18 |
# File 'lib/annals.rb', line 16 def lines @buffer.map {|event| "#{event[:file]}:#{event[:line]} #{event[:method]}"} end |
#puts ⇒ Object
20 21 22 23 24 |
# File 'lib/annals.rb', line 20 def puts for line in lines puts(line) end end |
#start ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/annals.rb', line 26 def start @buffer = [] @size = 0 Kernel.set_trace_func( lambda { |event, file, line, id, binding, classname| if event == 'call' unshift(:file => file, :line => line, :method => "in #{id}") end } ) end |
#stop ⇒ Object
38 39 40 41 |
# File 'lib/annals.rb', line 38 def stop Kernel.set_trace_func(lambda {}) @buffer.shift # remove Annals#stop from buffer end |
#unshift(line) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/annals.rb', line 43 def unshift(line) @buffer.unshift(line) if @size == @max @buffer.pop else @size += 1 end end |