Tap, Inject, and Each_With_Object

alt

I realized the other day that, while I’ve been using Object#tap, Enumerator#each#with_object, and Enumerable#each_with_object for some time now, I wasn’t completely clear on the difference between these methods or how best to employ them. Mostly I just threw in Object#tap wherever I saw sandwich code and called it a day.

Time for a…

alt

A good place to start is Ruby Docs for the method definitions:

Object#tap -
Yields self