When an application grows in size it’s common that it may slow down considerably in the face of heavy usage. Rather than looking at the larger picture its often best to take a microscope and look closely at the performance of the code, method by method, line by line. One tool that the Ruby Standard Library provides to assist with this is Benchmark. Lets take a quick dive into the features of the Ruby Benchmarking tool!
Most command line applications usually accept a variety of options that can be passed in to alter the behaviour of the application. For example, in linux, the
find command can take a
-type d option to specify only search for directories. For example the following command will find all empty directories under
The Observable module is a useful and elegant way to watch for changes in an object in Ruby. A common example is for alerting of some condition within the object being observed. The example shown in the documentation is for a
Ticker class which has two observers: one for when the price goes below a certain level and one for when the price goes above a certain level. What we will do today is show something similar, but for a
CoffeeShop class instead. Let’s get to it!
The Enumerable module in Ruby Core is very powerful. It provides methods such as sort, min, max and others for working specifically with collections. Its implemented by collection classes such as Array out of the box but what if you need to make your own custom collection class? In this case you will need to include the Enumerable module. Here’s how.