There is a “tap” method in Ruby and I find it is very useful.
The definitionof “tap” in ruby documentaion is:
1
Yields self to the block, and then returns self. The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.
Put it anonther way:
1
It’s a helper for call chaining. It passes its object into the given block and, after the block finishes, returns the object:
123
an_object.tapdo|o|# do stuff with an_object, which is in oend# ===> an_object