On Nov 12, 11:58 am, Josh Susser <j... / hasmanythrough.com> wrote:
> Ruby's enumeration message names come directly from its Smalltalk
> ancestry.  There are also some aliases.  Like so:
>
> *method*  *alias*
> collect   map
> detect    find
> select    find_all
> reject
> inject
>
> Ruby 1.9 introduces the K-combinator in the form of the method
> Object#tap.  I don't get the name #tap at all.  So I'm proposing a new
> name/alias pair, with a more meaningful name:
>
> *method*  *alias*
> affect    tap
>
> "foo".affect { |s| s << "bar" }
> #=> "foobar"
>
> 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.
>
> Thoughts?
>
> --
> Josh Susserhttp://blog.hasmanythrough.com

I remember some of this talk from RubyConf IRC, and I'm still not
convinced about "affect". Personally, I would expect a method called
"affect" to return the receiver with some change, whereas tap returns
the receiver as-is. Your example modifies the receiver in place, so
it's a little confounding.

MenTaLguY has yet to chime in, so I'll beat him to the punch with his
own link.  http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions
has some examples of what Object#tap is (possibly) intended for, and
that makes the name perfectly sensible, as far as I'm concerned. It's
for "tapping into" the line of calls, allowing you to see what's going
on at that point, but not changing anything.

Don't get me wrong, though. I'm all for more methods that end in
"ect".

I also find tap and returning to be for completely different purposes.
The point of the latter is mainly to get away from things like

def some_method
  var = ''
  some_stuff_with(var)
  var += something_else
  var.more_things
  var
end

and instead let you write something like

def some_method
  var = ''
  returning(var) do |x|
    some_stuff_with(x)
    x += something_else
    x.more_things
  end
end

--
-yossef
> --
> Posted viahttp://www.ruby-forum.com/.