From: William Djaja Tjokroaminata Date: 2002-04-14T04:19:40+09:00 Subject: Re: How to Make a Method Ineffective Efficiently? Hi, Do you have any experience or knowledge whether by doing it this way Ruby allocates more memory? Because in this way, every time debugMsg is called, the closure is created, and a closure in Ruby has a "state". If we call debugMsg many many times each with different closures, doesn't Ruby consume a lot of memory? Using a simple method call, such as debugMsg ("some message"), will not consume any more memory than necessary, I think; only the execution time may suffer. So the fundamental question is, when we use block/closure, does there exist a space-time trade-off or do we simply get the time advantage without any space problem? Thanks. Regards, Bill ==================================================================== Joe Mason wrote: > I just skimmed this, so sorry if I've missed the point (or a suggestion > that's already made) but in a recent project we used closures instead of > string parameters: > def debugMsg > $stderr.puts(yield) if $debug > end > debugMsg { "some message, which may take lots of processing" } > This way, if the debug variable isn't set, the closure never gets executed > because the yield statement never gets called. > Now, you said you couldn't use a single global variable, but you might be > able to adapt this idea. > Joe