Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Kernel#tap to be invoked with arguments like Kernel#send #2050

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Aug 18, 2019

  1. Allow Kernel#tap to be invoked with arguments like Kernel#send

    Tapping methods without any arguments already has nice shorthand via
    `Symbol#to_proc`:
    
    ```ruby
    object.tap { |o| o.example }
    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 a convenient 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 }
    object.tap(&:example)
    object.tap(:example)
    ```
    
    ---
    
    Ruby issue: https://bugs.ruby-lang.org/issues/15419
    shuber committed Aug 18, 2019
    Configuration menu
    Copy the full SHA
    52a1786 View commit details
    Browse the repository at this point in the history