开发者

Achieving `call_user_func_array` in Ruby

开发者 https://www.devze.com 2023-02-13 05:40 出处:网络
How can I accomplish http://php.net/manual/en/function.call-user-func-array.php in ruby? So I can do this:

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开发者_如何学C not scale
    end
end


Try exploding the array

App.send(:foo, *args)
0

精彩评论

暂无评论...
验证码 换一张
取 消