We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.
prepend an element to the start of an array
Array#push to append an element to the end of an array.
The names of these methods are not very intuitive.
Active Support from Rails already has aliases for the unshift and push methods , namely
In Ruby 2.5, these methods are added in the Ruby language itself.
1>> a = ["hello"] 2=> ["hello"] 3>> a.append "world" 4=> ["hello", "world"] 5>> a.prepend "Hey" 6=> ["Hey", "hello", "world"] 7>>
They are implemented as aliases to the original
push methods so there is no
change in the behavior.