是否可以将数组转换为函数的参数列表?

The*_*Fox 8 elixir

我有一个接受n多个参数的函数(它是devinus/sh函数),您可以在其中执行命令行程序并获得结果:

例: Sh.file "-b", "--mime-type", path_to_file

但我希望在数组中包含参数,以便它们可以根据函数的调用方式而变化.

我想要的例子:

data = ["-b", "--mime-type", path_to_file]

# a way of going through the array and turning it into the parameters for the Sh function

Sh.file <loop array params here>
Run Code Online (Sandbox Code Playgroud)

Sh不为参数采用数组.

有任何想法吗?

bit*_*ker 9

您可以使用apply(Sh, :file, args),args参数数组在哪里.