Building a Stack

After talking with one of the craftsmen about the dangers of using recursion (you can blow the stack -- hence, “stack overflow”) and how that can be avoided by using a while-loop instead, I took a cup of fresh coffee back to my standing workbench to digest what I had just learned. Flowing through my mind were thoughts about bits and bytes and the programming language C and why Java would be a better first language than Ruby because it forces you to consider things that Ruby automatically does under the hood. I put my forehead to the desk in a moment of mind blown-ness and when I picked it back up Jim was sitting next to me. “I want you to build a stack.” What was I to do but acquiesce? We got started with a bit of ping pong TDD.

The UML looks like this:

Stack Class
+ pop: int
+ peek: int
+ push(:int)

In about 30 minutes yesterday, this is what we came up with:

https://gist.github.com/pszals/5918354

How would you finish it out? I’ll update the rest once I complete it.