Issue #15419 has been updated by Eregon (Benoit Daloze).


shuber (Sean Huber) wrote:
> The `ruby/spec on Ruby 2.3` check is failing in this PR - I'm not sure what the existing conventions are for adding specs for new features like this.
> 
> * Should the new tests be wrapped in `unless RUBY_VERSION <= "2.3"` conditions?
> * Or should the new tests be added somewhere other than `/spec` instead?
> * Or some other convention? Please advise!

Yes, in such a case you need to use `ruby_version_is` guards as documented on https://github.com/ruby/spec/blob/master/CONTRIBUTING.md#guards,
because the behavior of previous versions will not change (unless this is decided to be backported, but very unlikely for a new feature, and even then the backport would be done later so the guards would be needed at first).

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

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