Project

General

Profile

Actions

Feature #14625

open

yield_self accepts an argument, calling to_proc

Added by irohiroki (Hiroki Yoshioka) over 6 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:86260]

Description

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.

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

Of course, we can get the same result with

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.

result = collection
  .yield_self(method :filter1)
  .yield_self(method :filter2)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0