+(p1)
public
Concatenation — Returns a new array built by concatenating the two arrays together to produce a third array.
[ 1, 2, 3 ] + [ 4, 5 ] #=> [ 1, 2, 3, 4, 5 ] a = [ "a", "b", "c" ] c = a + [ "d", "e", "f" ] c #=> [ "a", "b", "c", "d", "e", "f" ] a #=> [ "a", "b", "c" ]
Note that
x += y
is the same as
x = x + y
This means that it produces a new array. As a consequence, repeated use of += on arrays can be quite inefficient.
See also Array#concat.
Register or
log in
to add new notes.
joshuapinter -
January 4, 2012
mindloaf -
January 11, 2012
![Default_avatar_30](https://www.gravatar.com/avatar/6e6e22d81a1f4f394f62301be40c2e20?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Total Unique Elements from Two Arrays
Simple but thought it was worth mentioning:
( [ 1, 2, 3 ] + [ 3, 4, 5 ] ).uniq #=> [ 1, 2, 3, 4, 5 ]
![Default_avatar_30](https://www.gravatar.com/avatar/405f82a534decdf47041a5c8dc05ba3f?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Total Unique Elements: Set Union
For total unique elements, see set union: http://apidock.com/ruby/Array/|