From: spooq Date: 2006-11-17T22:49:04+09:00 Subject: Re: #returning and #tap On 11/17/06, Ross Bamford wrote: > On Fri, 17 Nov 2006 11:57:58 -0000, wrote: > > >> 'tap' had a different intent, though - "tee off the object without > >> disturbing it" - even if it did the same thing in the end. So you > >> would typically take a.foo.bar.baz.quux... and drop in a tap, > >> a.foo.bar.tap {|i| puts "hi mom! this is #{i}"}.baz.quux, and take > >> care not to modify i destructively. > > > > Although... there might be cases where disturbing the object would be > > desireable. For example, you could use it to work around the fact > > that a lot of bang methods return nil when there's no change: > > > > str = "abcde" > > a = str.tap {|s| s.gsub!(/z/,"x") }.split(//) > > > > Sweet! Noooooooooooo! Stop this meme now before it hurts someone!