1

I have two arrays of database records.

I'd like to add the second one to the beginning of the first.

I looked into insert, at a specific indexx, but it would result in inserting the second array inside the first one.

It might not be that hard, but thanks in advance for any help.

4

2 回答 2

5

这是怎么Array#+回事?

array2 = [1,2,3]
array1 = [11,21]

array2 + array1
# => [1, 2, 3, 11, 21]
于 2013-06-22T13:43:15.840 回答
3

Ruby 的救命稻草:

a = [1, 2, 3]
b = [4, 5, 6]

a.unshift(*b)
a #=> [4, 5, 6, 1, 2, 3]
于 2013-06-22T13:47:51.557 回答