Issue #6373 has been updated by phluid61 (Matthew Kerwin).


laise (Alexey Chernenkov) wrote:
> Quote: "I think that tap method can be improved to be used without block yielding self."
> 
> +1
> 
> It is a VERY usefull feature! Can't understand why #tap still need to be used with block only.

Because it's called "tap."  Tap doesn't "return self", it taps into an execution flow, extracting an intermediate value for inspection without interrupting the original flow.  The analogy is literally tapping a hole in a pipe, to extract liquid samples at various phases in a process.  (Also think of tapping a phone line.)  Changing its semantics to a straight-up "returns self" method would just make it idiosyncratic, instead of metaphoric.

Matz wrote:
> The point is when we see the code like:
>
>   [1,2,3,4,5,1,2,2,3].group_by(&:self)
>
> sometimes it would be less intuitive that self refers elements in the array, not self in the scope.

I have trouble imagining such a scenario.  I actually think the `some_array.group_by(&:self)` example is a strong plus for this feature.

I'm also not entirely convinced it's really YAM, since 'self' is already a word in the language, all we're doing is pushing it from keyword to keyword+method, i.e. making it more easily accessible from outside the instance.  Even more so since this use-case is really the only place it will ever show up; if there was another way to to_proc the 'self' keyword to make it easy to pass to a method like group_by I'd be for that as well/instead.
----------------------------------------
Feature #6373: public #self
https://bugs.ruby-lang.org/issues/6373#change-39732

Author: trans (SYSTEM ERROR)
Status: Feedback
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
This was recently suggested to me as an extension:

  class Object
    # An identity method that provides access to an object's 'self'.
    #
    # Example:
    #   [1,2,3,4,5,1,2,2,3].group_by(&:identity)
    #   #=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
    #
    def identity
      self
    end
  end

First, is such a method commonly useful enough to warrant existence?

Second, it makes me wonder if #self should be a public method in general.
=end


-- 
http://bugs.ruby-lang.org/