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

Interview Question on Ruby on Rails

Inserting and Moving elements inside Ruby Array