Learning about the many design patterns that are built into Ruby
Ruby internally uses many design patterns, supports design patterns in the core classes, and implements design patterns in some standard libraries. In this section, you'll learn about some common design patterns that Ruby uses by default.
The object pool design pattern
With the object pool design pattern, if you need a certain type of object, instead of allocating memory to create a new object, you can reuse an existing object. Ruby's garbage collection system is designed this way. Ruby would be significantly slower and much more prone to memory problems than it already is if it had to manually allocate memory from the operating system each time you created an object. Internally, Ruby uses the object pool pattern to improve object creation speed.
Other than immediate objects such as true
, false
, nil
, symbols, and most integers and floats, all other Ruby objects are stored in an object pool that is referred...