Issue #14625 has been updated by shevegen (Robert A. Heiler).


I can't answer all questions zverok posed but in regards to:

    .yield_self(method :filter2)

versus

    .yield_self(&method(:filter1))

The first variant is cleaner IMO.

As for (&.:filter1) I don't really like that suggestion and
I think it should not be connected to irohiroki's issue 
request here since he did not suggest it. :)

While I agree that it would be great if we could have a
way to also pass in arguments rather than just invoke
method calls vie e. g. array.map(&:strip) alone, I am
not convinced that **&.:** should be the way to go. It
looks very perlish and the dots are not so easily 
distinguishable. So on that, I think we should keep 
towards the suggestion itself given by irohiroki. And
I think he meant it only for yield_self, not for any
other method. Of course one can argue that symmetry 
should exist for all methods (though I am not sure as
to why, other than thinking that symmetry is more 
important even if it may be useless for some methods).


----------------------------------------
Feature #14625: yield_self accepts an argument, calling to_proc
https://bugs.ruby-lang.org/issues/14625#change-71176

* Author: irohiroki (Hiroki Yoshioka)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently, yield_self doesn't accept any argument other than a block.

But there are situations where I would like to pass a method object to yield_self. 
e.g.

~~~ ruby
result = collection
  .yield_self(&method(:filter1))
  .yield_self(&method(:filter2))
~~~


Of course, we can get the same result with

~~~ ruby
result = filter2(filter1(collection))
~~~

but the order of reading/writing doesn't match the order of thinking.

My request is for yield_self to accept a proc-ish object and call to_proc on it so that we can write the code as shown below, which is more readable.

~~~ ruby
result = collection
  .yield_self(method :filter1)
  .yield_self(method :filter2)
~~~





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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>