From: Josh Susser Date: 2007-11-13T04:03:34+09:00 Subject: Re: alias_method :tap, :affect Rick Denatale wrote: > On Nov 12, 2007 12:58 PM, Josh Susser wrote: >> >> The K-combinator is all about side-effecting the receiver object, so >> "affect" seems like a meaningful name for that functionality (whereas >> "effect" would be wrong!). "tap" is still cute, and rhymes with "map", >> so having both seems like a good Rubyish way to go. > > Of course, active-support also defines the same method as > Object#returning Not exatcly. #tap works on the receiver, #returning works on an argument. #tap is more object-oriented IMO. returning("foo") { |s| s << "bar" } "foo".affect { |s| s << "bar" } > I'm not sure how the Smalltalk intro ties in here. It's just to say how awsome methods that end in "ect" are, and why :-) > I can't recall a > method implementation of the k-combinator in common use in Smalltalk, > in most cases the message cascade syntax ending with an invocation of > #yourself, would serve the cases where the k-combinator is used: > > Ruby > > a = MyObject.new.tap do |o| # or returning, or affect > o.foo = 1 > o.bar = "whatever" > end > > Smalltalk > a = MyObject.new foo: 1; > bar: "whatever"; > yourself > > For Rubyists unfamiliar with Smalltalk, the message cascade triggered > by the ; meant send the message after the ; to the receiver of the > last message. Object#yourself was defined to return the receiver, and > was not typically overridden. That's exactly right. Cascaded messages were cool, and came right out of the stack machine nature of Smalltalk's bytecodes. And I've often longed for a #yourself method in Ruby, but usually only to get to the target of a proxy object. > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.