How can I get the return value from a Ruby function, but inside the set_trace_func callback?

S

Stephen Kellett

Hi folks,

When my code is executing my trace_function set using set_trace_func how
do I get the return value for a ruby return event? Say for example I had
a function

def myFunc(arg1, arg2)
result = arg1 * arg2
end

and my trace function has been called for the return event for the
myFunc() function. The function always returns the last data item
evaluated, which in this case is result. Can I determine this value from
inside the trace function? If I can how do I do so?

I've spent all this afternoon trying to do this (and the other problem
in my other question), examining the Ruby source, but can't work it out.
Hope someone can help me, or tell me it can't be done :-(

Stephen
 
J

J. D.

Stephen said:
Hi folks,

When my code is executing my trace_function set using set_trace_func how
do I get the return value for a ruby return event? Say for example I had
a function

def myFunc(arg1, arg2)
result = arg1 * arg2
end

and my trace function has been called for the return event for the
myFunc() function. The function always returns the last data item
evaluated, which in this case is result. Can I determine this value from
inside the trace function? If I can how do I do so?

I've spent all this afternoon trying to do this (and the other problem
in my other question), examining the Ruby source, but can't work it out.
Hope someone can help me, or tell me it can't be done :-(

Stephen

Stephen,

This is a complete shot-in-the-dark from a noob but have you tried
adding this as the last line of the function?

return result

I heard somewhere it negatively impacts performance to add an explicit
return statement in functions. Maybe the cause of this performace hit
will be the same thing that helps when tracing.

Good luck.
 
S

Stephen Kellett

J. D. said:
This is a complete shot-in-the-dark from a noob but have you tried
adding this as the last line of the function?

I have tried this. It didn't work - but even if it did, it defeats the
purpose. I need it to work without modifying the Ruby program.

Thanks all the same.

Stephen
 
G

gabriele renzi

J. D. ha scritto:
This is a complete shot-in-the-dark from a noob but have you tried
adding this as the last line of the function?

return result

I heard somewhere it negatively impacts performance to add an explicit
return statement in functions. Maybe the cause of this performace hit
will be the same thing that helps when tracing.

this was true, but it is'nt anymore, nobu "the patch bot" nokada
proposed a patch and that was accepted:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/91270
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top