PDA

View Full Version : assigning the "Call" of a method to a variable?


qaos
January 31st, 2007, 12:36 PM
Hi all,

I was wondering if there was a way to assign the "Call" of a method to a variable, such that you can use that variable inplace of the method call itself?

EX:
... code ...
if block_sent?
{
do stuff
result = call method_a(a, b)
do other stuff
} else
{
do stuff
result = call method_b(a, b)
do other stuff
} end
... code ...
Can I change the above code snippet to something like this:

... code ...
if block_sent?
myMethodCall <= 'call method_a(a, b)' else
myMethodCall <= 'call method_b(a, b)' end
{
do stuff
result = myMethodCall
do other stuff
}
... code ...

trying to reduce the amount of code, maintenance, and such. {do stuff and do other stuff} is code that is identical with the exception of the 1 call.

and this will not work due to the way the code is:

{
do stuff
if block_sent?
result = call method_a(a, b) else
result = call method_b(a, b) end
do other stuff
}