开发者

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


Try exploding the array

App.send(:foo, *args)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜