Ruby | Array push() function
Array#push() : push() is a Array class method which appends the given object(s) on to the end of this array.
Syntax: Array.push()
Parameter: Array
Return: appends the given object(s) on to the end of this array.
Example #1 :
# Ruby code for push() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [34, 5, 7] # push method example puts "push() method form : #{a.push(3)}\n\n" puts "push() method form : #{b.push()}\n\n" puts "push() method form : #{c.push(2)}\n\n" |
chevron_right
filter_none
Output :
push() method form : [18, 22, 33, nil, 5, 6, 3] push() method form : [1, 4, 1, 1, 88, 9] push() method form : [34, 5, 7, 2]
Example #2 :
# Ruby code for push() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = [nil, "abc", "nil", "dog"] # declaring array b = ["cow", nil, "dog"] # push method example puts "push() method form : #{a.push(2)}\n\n" puts "push() method form : #{b.push(1)}\n\n" puts "push() method form : #{c.push(0)}\n\n" |
chevron_right
filter_none
Output :
push() method form : ["abc", "nil", "dog", 2] push() method form : ["cow", nil, "dog", 1] push() method form : [nil, "abc", "nil", "dog", 0]
Recommended Posts:
- Ruby | push() function
- Ruby | SizedQueue push() function
- Ruby | Queue push() function
- Ruby Array () function with example
- Ruby | Array pop() function
- Ruby | Array take() function
- Ruby | Array <=> function
- Ruby | Array &() function
- Ruby | Array map() function
- Ruby | Array min() function
- Ruby | Array max() function
- Ruby | Array none?() function
- Ruby | Array zip() function
- Ruby | Array one?() function
- Ruby | Array select() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



