How to Use The Strategy Design Pattern in Ruby

Let’s talk about the strategy design pattern! This design pattern helps you change the main algorithm inside a method. You do this by passing in a class that implements this algorithm, instead of hardcoding it into the class. And when I say algorithm I don’t mean a fancy computer science algorithm, but any code that … Read more

The Decorator Design Pattern in Ruby

What is the decorator design pattern? And how can you use this pattern in your Ruby projects? The decorator design pattern helps you enhance an object by adding new capabilities to it without having to change the class. Let’s look at an example! Logging & Performance In this example we are making HTTP requests using … Read more

How To Create A Memory Leak in Ruby

There are a few articles out there about how to find memory leaks. But how about creating one? I think it will be an interesting exercise so you know what a memory leak looks like in Ruby. Let’s see some examples. A Simple Leak We can create a memory leak by simply adding new objects … Read more

Profiling Ruby’s Memory Allocation with TCmalloc

How does memory allocation work in Ruby? Ruby gets memory in chunks, called pages, new objects are saved here. Then… When these pages are full, more memory is needed. Ruby requests more memory from the operating system with the malloc function. This malloc function is part of the operating system itself, but there are alternative … Read more