在Ruby中实现`call_user_func_array`

时间:2011-02-25 15:54:20

标签: ruby

如何在ruby中完成http://php.net/manual/en/function.call-user-func-array.php

所以我可以这样做:

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

1 个答案:

答案 0 :(得分:8)

尝试爆炸数组

App.send(:foo, *args)