[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Method switching

Tom

9/5/2007 4:42:00 PM

I'm not sure I entirely understand what you are driving at... But if I do,
you have a couple of options. The first is to use case/when. The second is
to use metaprogramming, something Ruby lends itself to. I'm no master of
that voodoo, but I'm sure someone else can chime in who is more familiar :)
If you could give a clearer example of what you need, it might be easier,
too.

tom


On 9/5/07 10:23 AM, "Lee Jarvis" <jarvo88@gmail.com> wrote:

> 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
>
> thanks in advance..