From: William Djaja Tjokroaminata Date: 2002-04-12T22:37:36+09:00 Subject: Re: How to Make a Method Ineffective Efficiently? Thanks for all the responses. I just want to add the final clarifications. Joseph McDonald wrote: > Why do you call print_info with the string representations of the > variables? Why not just call it with the variables themselves and > have print_info call the to_s if needed? Or am I missing something? I have used the method to_s only as an example; the actual problem that I am dealing with is more complicated than the simple debugging example (I am dealing with statistics, traces, and animations). Besides, even if I just pass the variables themselves, I still may pass too many arguments, where in fact the method does nothing with those arguments. Jean-Hugues ROBERT wrote: > def debug( &proc ) > if @@debug_debugging then > @@debug_file.write "Debug: @{proc.call()} > end > end > end > then use it: > debug{ "An inefficient msg: @{xxx()} Actually because I will call the method debug too many often in too many places, I want the procedure following the debug method call to be as simple as possible. The heavy processing is done in the body of the method debug itself. I have managed to transform the code. Just one clarification that remains: Is it true that we should never, EVER, use the "return" statement in a code block in Ruby? For example, def debug () if @debugging data = yield puts "data = #{data}" .... # do processing with data[0], data[1], ..., data[n] end end debug () {return a, b, c} This does not work! Regards, Bill