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.
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.
Link to Ruby documentation for tap
.