0048 Tap

For method chaining

The tap method, defined in Kernel, returns self which is passed as a block argument. To be distinguished from then, which returns the result of the block.

0048-tap_1.png

The main benefit is to be able to alter the object in the method chain. Another use case is to be able to inspect an intermediate state without having to rewrite everything.

0048-tap_2.png

Link to Ruby documentation for tap.