© Carleton DiLeo 2019
Carleton DiLeoClean Rubyhttps://doi.org/10.1007/978-1-4842-5546-9_5

5. Classes

Carleton DiLeo
(1)
Boulder, CO, USA
 
In this chapter, we cover several techniques you can use to make high-quality classes.

Initialize Method

When instantiating a class in Ruby, the new class method calls the initialize instance method. Any parameters passed to the new method will be passed to the initialize method. The initialize method is a setup method for a class. It’s called before any other method defined in the class. If we have steps to perform before using the class, we place them in the initialize method. Let’s look at techniques we can use to improve our initialize methods.

Keep It Simple

The initialize method should be simple, which means ...

Get Clean Ruby: A Guide to Crafting Better Code for Rubyists now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.