Saturday, January 18, 2025
.tap
https://ruby-doc.org/3.4.1/Kernel.html#method-i-tap
tap {|x| block } → obj
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.
What a weird method, but a method that seems pretty useful.
I have used tap
to capture output from a running docker container to shove into a cache that was fed to users via action cable. I can see how useful it would be for debugging and testing though too. At least if you werent using pry.
Outside of that, I actually do like how it looks as a way to organize code. I can see that being contentious in the community though