Issue #14625 has been updated by irohiroki (Hiroki Yoshioka).


zverok,

Answer 1.

~~~ ruby
.yield_self(method :filter1)
~~~

is shorter than

~~~ ruby
.yield_self(&method(:filter1))
~~~

and doesn't have nested parens.

Answer 2: I don't really know about other methods, but there is a method named Enumerable#inject and actually it accepts a symbol as an argument that is special among methods having a block. What I mean is that there can be a special method, although I'm not sure it's really nice.

Regarding #13581, it can help me but anyway it's still open right now.

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

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