New aliases "append" to Array#push, and "prepend" to Array#unshift (since Ruby 2.5.0)
Ruby introduces new methods aliases Array#append
to Array#push
and Array#prepend
to Array#unshift
since the version 2.5.0.
[Feature #12746]
[Commit f57d515d69b7a35477b9ba5d08fe117df1f1e275]
Let’s refresh our knowledge about the methods Array#push
and Array#unshift
and keep in mind about the aliases!
push(obj, … ) => ary
Append — Pushes the given object(s) on to the end of this array. This expression returns the array itself, so several appends may be chained together. See also #pop for the opposite effect.
a = [ "a", "b", "c" ]
a.push("d", "e", "f")
#=> ["a", "b", "c", "d", "e", "f"]
[1, 2, 3].push(4).push(5)
#=> [1, 2, 3, 4, 5]
unshift(obj, …) => ary
Prepends objects to the front of self, moving other elements upwards. See also #shift for the opposite effect.
a = [ "b", "c", "d" ]
a.unshift("a") #=> ["a", "b", "c", "d"]
a.unshift(1, 2) #=> [ 1, 2, "a", "b", "c", "d"]
Active Support Core Extensions provide aliases Array#append
and Array#prepend
since Rails 3.2.0 (January 20, 2012).
Since Ruby 2.5.0 Active Support Core Extensions prevent creating aliases Array#append
and Array#prepend
in favor of the implementation of them in Ruby [Pull Request #28638].
Active Support helps to bring new ideas/futures in the Ruby, it is one of the main reason to respect it.