From: Robert Klemme Date: 2007-09-06T01:43:32+09:00 Subject: Re: Method switching 2007/9/5, Lee Jarvis : > Ok this probably won't make any send at all, but lets say i have > something like this: > > def send(a) > puts "#{a}\n" > end > > def colorsend(a) > puts "#{colorize(a)}\n" > end > > def something > send "hello" > end > > > > Ok lets say i have 50+ methods like the something method, that relate to > the send method, i want to be able to have 1 switch to change the method > without changing every method that uses send(message) > for example i could use > > if @color = 1 > colorsend(msg) > else > send(msg) > end > > but that means i would have to add that to *every* method.. if anyone at > all out there understands what i mean it would be very helpful Since you are dispatching based on an instance variable, why don't you wrap send and colorsend in another method that does the dispatching and invoke this other method from your 50+ methods? Btw, send is a bad name to choose because this is a standard method. I also wonder why you have 50+ methods that are somehow similar. It seems there is room for improvement. Maybe you can state the business problem you are trying to solve. Cheers robert