From: Josh Susser Date: 2007-11-13T04:44:02+09:00 Subject: Re: alias_method :tap, :affect Martin DeMello wrote: > On Nov 12, 2007 11:10 AM, wrote: >> >> This is the first I've heard of Object#tap. It seems backward because >> you almost always want the result of the block, not the object back >> again. > > #tap is the opposite use case - you want to "tap" the object stream, > observing without affecting. It's very handy for debugging, where you > can tap into a chain of method calls, print something out and continue > on your way, e.g. > > foo.map(&:bar).tap {|a| p a}.inject... > > martin That's a great example of a use-case for #tap. (I think I remember that from the original discussion of the feature.) But the K-combinator style side-effect is valid too. Just look at all the uses of #returning in Rails. -- Posted via http://www.ruby-forum.com/.