Kyl*_*cey 4 ruby arrays arguments apply
想转换这个:
[["1", "2", "3"], ["4", "5", "6"]]
Run Code Online (Sandbox Code Playgroud)
对此:
["1", "2", "3"], ["4", "5", "6"]
Run Code Online (Sandbox Code Playgroud)
要传递到Array.product(),第一个数组可以包含未知数量的其他数组.例如,给出的数组也可以是
[["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]
Run Code Online (Sandbox Code Playgroud)
最后,我需要将论证传递为:
otherArray.product(["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"])
Run Code Online (Sandbox Code Playgroud)
提前谢谢!
otherArray.product(*[["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"]]);
Run Code Online (Sandbox Code Playgroud)
*在参数列表中用于将数组内容解包到参数(如此处)或将参数打包到数组中,例如"def mymethod(*args)"
参考:http://www.justskins.com/forums/apply-method-to-array-17387.html