Ruby Array : Push and Pop

Push

chars = ["a", "b", "c"]
=> ["a", "b", "c"]

chars.push "d"
=> ["a", "b", "c", "d"]

chars.push "e"
=> ["a", "b", "c", "d", "e"]

Pop : Last In First Out (LIFO)

chars
=> ["a", "b", "c", "d", "e"]

chars.pop
=> "e"

chars.pop
=> "d"

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Difference between Validations, Callbacks and Observers