If you want to learn how to write Rake tasks, this tutorial is right for you!
You're going to learn what the build tools are in general. I will show you how to write your first simple Rake task and how to express dependencies between tasks. I will also cover some useful FileUtils methods.
Get intimate with Rake now!
Generally, it is a good idea to automate every boring, complicated programming task that often needs to be repeated. Firstly, developer's time and nerves can be spared. Secondly, the risk of doing something wrong (e.g. making a typo or leaving out one of the steps required) is minimized. Prepare the task once and don't repeat yourself anymore.
There are many tools available and the choice is determined principally by the language and environment we use. Some of the most well-know tools are make, Ant, Phing, Capistrano and Rake. In this short article, we are going to show how to write simple but powerful Rake task to run RSpec tests with code coverage meter.
A Hash in Ruby is a data structure that holds values in the key => value fashion. The Hash class provides many useful methods, some of them come from the Enumerable module. We won't go through all of them now, we'll rather focus on the often forgotten, but worth its value method: default().
We are also going to introduce the Null Object design pattern and show how it can be combined with the default() hash method.
Sometimes, when we are working with objects in Ruby, we want to make a copy of them. But what for? Well, in most cases we want to have a working copy and still maintain the original, intact object. Changing a reference back to the primary object is much simpler than repairing object's state.
As we are going to show, Ruby object cloning may sometimes behave in an unexpected way. We are going to show why weird things happen and how to force Ruby to clone objects in the way we want. We will use clone method implementation and marshalling mechanism.