ruby将数组转换为函数参数


96

说我有一个数组。我希望将数组传递给函数。但是,该函数需要两个参数。有没有一种方法可以快速将数组转换为2个参数?例如:

a = [0,1,2,3,4]
b = [2,3]
a.slice(b)

在Ruby中会产生错误。我需要输入,a.slice(b[0],b[1])我正在寻找更优雅的东西,例如,a.slice(foo.bar(b)) 谢谢。


Answers:



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.