Push an array to another array : Push « Array « Ruby






Push an array to another array


p a = [1,2,3]                             # => [1, 2, 3]
p a << [4, 5, 6]                          # => [1, 2, 3, [4, 5, 6]]
p a << a                                  # => [1, 2, 3, [4, 5, 6], [...]]

 








Related examples in the same category

1.Blow Your Stack
2.You can add things to the end of the array by pushing data into it
3.With arrays, << is the operator for pushing an item onto the end of an array.
4.Push integer and string to the same array