I've found this piece of code in a pull request someone made to one of my gems:
source = HTTParty.get(PoliticosBR::DEPUTADOS_URL)
tempfile = Tempfile.new('deputados.xls').tap do |f|
#tap is defined on
It was introduced in Ruby 1.9. It yields self to the block and then returns self. I think an illustrative example is when it's used to return an object from a method.
You could do this.
def foo a =  a.push(3) a end def foo .tap do |a| a.push(3) end end
In the first example the array a is returned explicitly and in the second tap is being used to yield the block to self and then return self.