Quick reference for array methods: push/pop vs. shift/unshift

Donna Hogan
1 min readSep 11, 2017

--

I love to make tables to help me integrate ideas or objects and how they relate to each other.

When I was learning how to work with arrays in Ruby, the words for functions .push, .pop, .shift, and .unshift, didn’t carry any intrinsic meaning or distinction to me in terms of working with an array (unlike .collect, and .size, which do). I kept getting confused about which thing returns an element, and which one returns the rest of the array, and whether it acts on the beginning or the end. So, here’s my table!

  • and of course, << (shovel) is syntactic sugar for .push

Originally published at donnacodes.com on September 11, 2017.

--

--

Donna Hogan

coding student, jack of many trades with a master’s in biochem. Feat. data science & dysautonomia. disabled/chronic, &sometimes♿️ (She/Her)