From: oleynikov@...
Date: 2018-12-16T10:58:02+00:00
Subject: [ruby-core:90562] [CommonRuby Feature#15419] Allow Kernel#tap to be invoked with arguments like Kernel#send

Issue #15419 has been updated by oleynikov (Alexander Oleynikov).


It is not backward compatible.
And I'm not sure why we need to change just `#tap` and not other methods.

There are some discussions going on about passing arguments whith `Symbol#to_proc` shorthand: #12115, #15301, etc. Personally I'd rather see one of these implemented. It would also fix this issue.

----------------------------------------
Feature #15419: Allow Kernel#tap to be invoked with arguments like Kernel#send
https://bugs.ruby-lang.org/issues/15419#change-75712

* Author: shuber (Sean Huber)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Tapping methods without any arguments already has nice shorthand via `Symbol#to_proc`:

```ruby
object.tap { |o| o.example }
# vs
object.tap(&:example)
```

Unfortunately once other arguments are involved we have to switch back to the longer form:

```ruby
array.merge(other).tap { |a| a.delete(object) }
```

[This patch introduces](https://github.com/ruby/ruby/pull/2050) a convenient and familiar shorthand for these cases which behaves similar to `Kernel#send`:

```ruby
array.merge(other).tap(:delete, object)
```

Calling tap without any arguments or block still raises `LocalJumpError`:

```ruby
3.tap #=> LocalJumpError: no block given
```

This also makes the existing shorthand even shorter:

```ruby
object.tap { |o| o.example }
# vs
object.tap(&:example)
# vs
object.tap(:example)
```

---

**Pull request**: https://github.com/ruby/ruby/pull/2050



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