def traceExit
puts ("EXIT " + caller[0])
puts "\n"
end
and then do
def method1 (arg1 = 0, arg2 = false, arg3 = 'hello')
traceEntry ("arg1" => arg1, "arg2" => arg2, "arg3" => arg3)
begin
# do some stuff
ensure
# record even in case of an exception
traceExit
end
end
I'm using ruby 1.6.8 (2002-12-24) [i586-mswin32]
What I tinkered for tracing is (simplified) this:
Ruby 1.8.0 contains a tracer.rb as part of the Standard Library. I'm not sure whether it already existed in Ruby 1.6.8, but maybe you can make some usage of it or its source code.
>
> > My question is:
> > How do I know the names of the formal arguments of the actual caller
of
> > TraceEntry ?
>
> You can't other that providing them explicitely, for example by using
a
> hash:
>
I already thougt about a hash-solution, but I hoped to get something
like a
hash implicitely,
such minimizing work and possible typo errors.
Not without doing work somewhere else. You could somehow evaluate
__FILE__ and __LINE__ or caller to get the source line number and try to
extract argument names from the source file. But this is error prone and
doesn't work well with eval and such.