Sorry, code should be

require 'tracer'

Tracer.on

class SomeClass
  def someMethod
    puts "caller #{caller}"
  end
end

Tracer.off
someClass = SomeClass.new
someClass.someMethod

Bart Masschelein wrote:

> Hello all,
>
> Is there a reason why these lines of code:
>
> require 'tracer'
>
> Tracer.on
>
> class SomeClass
>  def someMethod
>    puts "Some text"
>  end
> end
>
> produce the following output:
>
> #0:TracerTest.rb:3:Tracer:<: Tracer.on
> #0:TracerTest.rb:3:Tracer:<: Tracer.on
> #0:TracerTest.rb:5::-: class SomeClass
> #0:TracerTest.rb:5:Class:>: class SomeClass
> #0:TracerTest.rb:5:Class:<: class SomeClass
> #0:TracerTest.rb:5::C: class SomeClass
> #0:TracerTest.rb:6::-:   def someMethod
> #0:TracerTest.rb:6:Module:>:   def someMethod
> #0:TracerTest.rb:6:Module:<:   def someMethod
> #0:TracerTest.rb:5::E: class SomeClass
> #0:TracerTest.rb:11::-: Tracer.off
> caller TracerTest.rb:13
>
> Why isn't it :
>
> #0:TracerTest.rb:3:Tracer:<: Tracer.on
> #0:TracerTest.rb:3:Tracer:<: Tracer.on
> #0:TracerTest.rb:5::-: class SomeClass
> #0:TracerTest.rb:5:Class:>: class SomeClass
> #0:TracerTest.rb:5:Class:<: class SomeClass
> #0:TracerTest.rb:5::C: class SomeClass
> #0:TracerTest.rb:6::-:   def someMethod
> #0:TracerTest.rb:6:Module:>:   def someMethod
> #0:TracerTest.rb:8:Module:<:   def someMethod
> #0:TracerTest.rb:9::E: class SomeClass
> #0:TracerTest.rb:11::-: Tracer.off
> caller TracerTest.rb:13
>
> So you know when browsing through the require tree, on which line a 
> class or method begins, and where it ends. I guess it is not a Tracer 
> issue, but rather a set_trace_func method(), by the return values you 
> get.
>
> This would be useful, as you could first make a model of your code by 
> changing the Tracer, and when the execution starts, stopping the 
> Tracer, as it reduces the overhead (because of the 
> set_trace_func_method() with some filters on). Then later, you can 
> call caller, and by the filename and linenumber exactly know where 
> this fits in the model.
>
> Or are there other ways to do this?
>
> Bart.
>
>
>
>
>
>
>