Introduction
In the previous chapter, we learned about Boolean variables, conditional expressions, and loops, including the core Ruby concepts of using blocks. We will now zoom out a little in the Ruby world and learn about methods. In fact, we've been using methods in the previous chapters, and we will look at them in more depth now.
Methods are foundational units in Ruby. They allow you to wrap code in chunks that can be called with different parameters to get different outputs. Methods commonly have descriptive names and, as such, make clear what the underlying bundle of code does. For instance, we previously learned about the each
method on arrays. This method enumerates over each item in the array, and so is very descriptive. In fact, method naming is an art where you balance simplicity with descriptiveness. It is considered that the difficult things in computer science are caching, naming things, and off-by-one errors. Commonly known as OBOB errors, off-by-one bugs are...