From: Alan Chen Date: 2004-07-17T05:42:13+09:00 Subject: Re: Dynamically replacing methods for efficiency Hal Fulton wrote: > On the one hand, I appreciate Ruby because I *can* do this > sort of thing. On the other hand, if the logic for #action > changes, how many pieces of code will I find myself modifying? Exactly, you *never* want to code yourself into a corner where one change in logic needs to be refelected in parallel branches - especially when your involving diagnostic code. DRY! A different way to approach your problem is to have a smarter tracer object which performs a noop when its inactive. def action @tracer.puts "Entering action" do_this @tracer.puts "Returned from do this" do_that @tracer.puts "Returned from do that" end Your trace setter would activate the tracer which would swap between a noop puts method and a working puts method. Now, I've aproached things this way in C++ where a noop is very cheap, I'm not sure of the execution cost of a method lookup vs an if statement in ruby. Either way, I think it's still conceptually cleaner to use a smart tracer, logger object.