Issue #14625 has been updated by zverok (Victor Shepelev).



Question 1. How is this (proposed):

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

better than this (already works):

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

?

Question 2: what about all other methods that accepts blocks of code? If the syntax shown above is available for `#yield_self`, shouldn't it become available for `#each`, `#map` and everything else?..

```ruby
collection.yield_self(method :filter1)
collection.map(method :filter1)
```

I believe that the real improvement of "passing the method" situation would be the #13581, so you can write something like:

```ruby
collection
  .yield_self(&.:filter1)
  .yield_self(&.:filter2)
```


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

* 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>