📜  红宝石 |推()函数

📅  最后修改于: 2022-05-13 01:55:07.573000             🧑  作者: Mango

# 红宝石 |推（）函数

Ruby 中的 push()函数用于将给定元素推送到给定数组的末尾，并返回包含推送元素的数组本身。

``````# Initializing some arrays of elements
Array1 = [1, 2, 3, 4]
Array2 = ["a", "b", "c"]
Array3 = ["gfg", "Geeks", "GeeksforGeeks"]

# Calling push() function
A = Array1.push(5, 6, 7)
B = Array2.push("d", "e", "f")
C = Array3.push("Geek")

# Printing the array of pushed element
puts "#{A}"
puts "#{B}"
puts "#{C}"
``````

``````[1, 2, 3, 4, 5, 6, 7]
["a", "b", "c", "d", "e", "f"]
["gfg", "Geeks", "GeeksforGeeks", "Geek"]
``````

``````# Initializing some arrays of elements
Array1 = [10, 20, 30, 40]
Array2 = ["Z", "Y", "X"]
Array3 = ["ab", "abc", "abcd"]

# Initializing some elements
# which are to be pushed
p = 50, 60
q = "W", "V", "U"
r = "abcde", "abcdef"

# Calling push() function
A = Array1.push(p)
B = Array2.push(q)
C = Array3.push(r)

# Printing the array of pushed element
puts "#{A}"
puts "#{B}"
puts "#{C}"
``````

``````[10, 20, 30, 40, [50, 60]]
["Z", "Y", "X", ["W", "V", "U"]]
["ab", "abc", "abcd", ["abcde", "abcdef"]]
``````