Ruby #tap method

Ruby Object#tap method is a pretty cool method that can improve the readability of your code.

tap was introduced in Ruby 1.9, what it does is pretty simple: it yields a value to a block and then returns it.

It’s especially useful when you need to populate an hash or a variable and return the value, it allows you to cut those intermediate variables.

For example you can turn this:

Liquid error: No such file or directory - posix_spawnp

into this:

Liquid error: No such file or directory - posix_spawnp

In my opinion, the second example is much better, it is easier to read and parse rapidly.