Ruby | Array push() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 # 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" 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 # 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" Output : push() method form : ["abc", "nil", "dog", 2] push() method form : ["cow", nil, "dog", 1] push() method form : [nil, "abc", "nil", "dog", 0] Comment More infoAdvertise with us Next Article Ruby | Array push() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array pop() function Array#pop() : pop() is a Array class method which checks removes the last element from the array and returns it. Syntax: Array.pop() Parameter: Array Return: removes the last element from the array and returns it. Example #1 : Ruby # Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 1 min read Ruby | Array map() function Array#map() : map() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3 2 min read Ruby | Array pack() function Array#pack() : pack() is a Array class method which returns the contents of arr into a binary sequence according to the directives in aTemplateString Syntax: Array.pack() Parameter: Array Return: the contents of arr into a binary sequence according to the directives in aTemplateString Example #1 : R 1 min read Ruby | Array to_h() function Array#to_h() : to_h() is a Array class method which returns the result of interpreting ary as an array of [key, value] pairs. Syntax: Array.to_h() Parameter: Array Return: the result of interpreting ary as an array of [key, value] pairs. Example #1 : Ruby # Ruby code for to_h() method # declaring ar 1 min read Ruby | push() function The push() function in Ruby is used to push the given element at the end of the given array and returns the array itself with the pushed elements. Syntax: push(Elements) Parameters: Elements : These are the elements which are to be added at the end of the given array. Returns: the array of pushed el 2 min read Ruby | Array product() function Array#product() : product() is a Array class method which returns an array of all combinations of elements from all arrays. Syntax: Array.product() Parameter: Array Return: an array of all combinations of elements from all arrays. Example #1 : Ruby # Ruby code for product() method # declaring array 2 min read Ruby | Array one?() function Array#one?() : one?() is a Array class method which checks whether the array is having only one array element. Syntax: Array.one?() Parameter: Array Return: true - if array has only one element otherwise return false. Example #1 :Â Ruby # Ruby code for one?() method # declaring array a = [18, 22, 33 1 min read Ruby | Array length() function Array#length() : length() is a Array class method which returns the number of elements in the array. Syntax: Array.length() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for length() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array 1 min read Ruby | Array none?() function Array#none?() : none?() is a Array class method which checks whether the array is empty or not. Syntax: Array.none?() Parameter: Array Return: true - if array has no elements otherwise return false Example #1 : Ruby # Ruby code for none?() method # declaring array a = [18, 22, 33, nil, 5, 6] # decla 1 min read Ruby | Array replace() function Array#replace() : replace() is a Array class method which returns an array of all combinations of elements from all arrays. Syntax: Array.replace() Parameter: Array Return: an array of all combinations of elements from all arrays. Example #1 : Ruby # Ruby code for replace() method # declaring array 2 min read Like