[英]Is it possible to turn an array into a list of parameters for a function?
I have a function that accepts n
number of parameters (it's the devinus/sh function) where you can execute a command line program and obtain the results: 我有一个函数接受
n
个参数(它是devinus / sh函数),你可以在其中执行命令行程序并获得结果:
Example: Sh.file "-b", "--mime-type", path_to_file
示例:
Sh.file "-b", "--mime-type", path_to_file
But I want to have the parameters in an array so they can be varying depending on how the function is called. 但我希望在数组中包含参数,以便它们可以根据函数的调用方式而变化。
Example of what I want: 我想要的例子:
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>
Sh doesn't take an array for a parameter. Sh不为参数采用数组。
Any ideas? 有任何想法吗?
你可以使用apply(Sh, :file, args)
,其中args
是一个参数数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.