Ruby:有没有一种方法可以在一行中使用索引数组从数组中获取值?

Ruby:有没有一种方法可以在一行中使用索引数组从数组中获取值?,ruby,Ruby,注意,您必须打开indexes参数,接受整数或范围列表作为参数 请注意,您必须打开indexes参数,接受整数或范围列表作为参数BAH!我需要等10分钟才能选择这个作为答案=pBAH!我需要等10分钟才能选择这个作为答案=P array: [1,2,1,1,2,2,2,1,1,1,1,1] indexes: [0,3,5,1] output: [1,1,2,2] output = array.values_at(*indexes)

注意,您必须打开indexes参数,接受整数或范围列表作为参数


请注意,您必须打开indexes参数,接受整数或范围列表作为参数

BAH!我需要等10分钟才能选择这个作为答案=pBAH!我需要等10分钟才能选择这个作为答案=P
array: [1,2,1,1,2,2,2,1,1,1,1,1]
indexes: [0,3,5,1]
output: [1,1,2,2]
output = array.values_at(*indexes)