Project

General

Profile

Actions

Feature #12760

closed

Optional block argument for `itself`

Added by zverok (Victor Shepelev) over 7 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:77267]

Description

That's an another attempt to choose good metaphor for object.(yield self) (previously: #6721 and ton of duplicates).

In discussion here: https://bugs.ruby-lang.org/issues/11717#note-3 it was said:

Clearly this is something the Ruby community wants. Just as clearly, it's something nobody can name.

But suddenly... I've thought about this!

some.long.method.chain.constructing.string
  .itself { |s| "(" + s + ")" }
  .itself(&method(:puts))

# or
require 'open-uri'

construct_url(*params)
  .itself(&method(:open))
  .read
  .itself(&JSON.method(:parse))
  .to_yaml
  .itself(&File.method(:write))

# NB: I understand that _last_ `itself` in both examples
#     could as well be `tap`. But not all the previous.

Pros:

  • method is already here, it has pretty name and underused (almost nothing except group_by(&:itself) comes to mind);
  • it is not 100% good English, but readable: itself(&JSON.method(:parse)) = "parse itself with json";
  • implementation is trivial, no backwards-compatibility issues (like new methods shadowing something important in third-party library) are expected.

Cons:

  • ???

Related issues 7 (0 open7 closed)

Is duplicate of Ruby master - Feature #6721: Object#yield_selfClosedmatz (Yukihiro Matsumoto)Actions
Is duplicate of Ruby master - Feature #6684: Object#doRejected07/02/2012Actions
Is duplicate of Ruby master - Feature #7388: Object#embedRejectedmatz (Yukihiro Matsumoto)11/19/2012Actions
Is duplicate of Ruby master - Feature #10095: Object#asClosedActions
Is duplicate of Ruby master - Feature #11717: Object#trap -- pass object to block and return resultClosedActions
Has duplicate Ruby master - Feature #13172: Method that yields object to block and returns resultClosedActions
Has duplicate Ruby master - Feature #13559: Change implementation of Feature #6721FeedbackActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0