Alex Fenton
2/8/2009 4:28:00 PM
Boris Schmid wrote:
> Apologies, I have been out of using ruby for a while, and ran into
> trouble when I tried to do the below. What is the normal way to call
> apply a list of arguments to a list of functions?
>
> def f1(n)
> puts "f1: #{n}"
> end
>
> def f2(n)
> puts "f2: #{n}"
> end
[:f1, :f2].each do | fun |
[1, 2, 3, 4].each { | x | Object.send(fun, x) }
end
Ruby doesn't have functions, just methods. What look like functions
above (a def outside a class body) creates methods in the Object class.
"send" is the generic way to call any object's method using a name. It
accepts a string or symbol (hence :f1 above) followed by the arguments.
a