Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achieving `call_user_func_array` in Ruby

Tags:

ruby

How can I accomplish http://php.net/manual/en/function.call-user-func-array.php in ruby?

So I can do this:

class App
    def foo(a,b)
        puts a + b
    end
    def bar
        args = [1,2]
        App.send(:foo, args) # doesn't work
        App.send(:foo, args[0], args[1]) # does work, but does not scale
    end
end
like image 646
balupton Avatar asked Feb 25 '11 15:02

balupton


1 Answers

Try exploding the array

App.send(:foo, *args)
like image 121
johusman Avatar answered Oct 05 '22 05:10

johusman