Push integer and string to the same array : Push « Array « Ruby






Push integer and string to the same array


a = [1, 2, 3]                           # => [1, 2, 3]
p a << 4.0                                # => [1, 2, 3, 4.0]
p a << 'five'                             # => [1, 2, 3, 4.0, "five"]

 








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 an array to another array