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.
The tap method has been in Ruby since 1.8.7:
tap{|x|...} => obj
Yields
xto the block, and then returnsx. 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.
The Object#tap monkey patch from ActiveSupport is deprecated because it has been part of Ruby since 1.9.0 and 1.8.7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With