---
title: "Array#prepend and Array#append in Ruby 2.5"
description: "Better names for existing Array#unshift and Array#push methods"
canonical_url: "https://www.bigbinary.com/blog/array-prepend-and-array-append-in-ruby-2-5"
markdown_url: "https://www.bigbinary.com/blog/array-prepend-and-array-append-in-ruby-2-5.md"
---

# Array#prepend and Array#append in Ruby 2.5

Better names for existing Array#unshift and Array#push methods

- Author: Prathamesh Sonpatki
- Published: December 19, 2017
- Categories: Ruby 2.5, Ruby

Ruby has `Array#unshift` to prepend an element to the start of an array and
`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](https://github.com/rails/rails/blob/e48704db8e6021b690b1fe2b362c7cb2e624e173/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb)
, namely `prepend` and `append`.

In Ruby 2.5, these methods
[are added in the Ruby language itself](https://bugs.ruby-lang.org/issues/12746).

```ruby
>> a = ["hello"]
=> ["hello"]
>> a.append "world"
=> ["hello", "world"]
>> a.prepend "Hey"
=> ["Hey", "hello", "world"]
>>
```

They are implemented as aliases to the original `unshift` and `push` methods so
there is no change in the behavior.

## Links

- [Human page](https://www.bigbinary.com/blog/array-prepend-and-array-append-in-ruby-2-5)
