[ruby-core:90553] [CommonRuby Feature#15419] Allow Kernel#tap to be invoked with arguments like Kernel#send

From: sean.m.huber@...
Date: 2018-12-15 20:51:57 UTC
List: ruby-core #90553
Issue #15419 has been reported by shuber (Sean Huber).

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

* 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](https://github.com/ruby/ruby/pull/2050) introduces 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
```

---

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



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next