tap? It’s a helper for call chaining. It passes its object into the given block and, after the block finishes, returns the object:
an_object.tap do |o| # do stuff with an_object, which is in o end # ===> an_object
The benefit is that
tap always returns the object it’s called on, even if the block returns some other result. Thus you can insert a
tap block into the middle of an existing method pipeline without breaking the flow. MenTaLguY has some nifty examples of other things you can do with
Fans of Ruby on Rails may recognize
tap as similar to RoR’s own
Looks like Ruby 1.9 is going to be extra cool for a number of reasons.