tap method in Rails 3 - Have I understood the API Docs correctly?
ruby, ruby-on-rails, ruby-on-rails-3.2
Solution
The `tap` method has been in Ruby since 1.8.7:
tap{|x|...} => obj
Yields `x` to the block, and then returns `x`. The primary purpose of this method is to “tap into” a method chain, in order to perform operations on intermediate results within the chain.
Note that 1.8.6 did not have `Object#tap`. Presumably, `tap` was in older versions of Rails (as a monkey patch on `Object`) but was added to Ruby itself in 1.8.7. Since 1.8.6 is rather ancient now, the Rails version was deprecated and, in more recent Rails releases, removed entirely.
`Object#tap` is still around so `tap` itself has not been deprecated, just the Rails monkey patched version has been removed.
Problem
I'm upgrading a rails 2 application to rails 3.2 and have come across what is described as an idiom. `person.tap |p| do` When I Googled for this and it appears to have been deprecated or moved. Is my understanding correct? I ask because I can find a few examples of it on SO.