Actions
Feature #15419
openAllow Kernel#tap to be invoked with arguments like Kernel#send
Status:
Open
Assignee:
-
Target version:
-
Description
Tapping methods without any arguments already has nice shorthand via Symbol#to_proc
:
object.tap { |o| o.example }
# vs
object.tap(&:example)
Unfortunately once other arguments are involved we have to switch back to the longer form:
array.merge(other).tap { |a| a.delete(object) }
This patch introduces a convenient and familiar shorthand for these cases which behaves similar to Kernel#send
:
array.merge(other).tap(:delete, object)
Calling tap without any arguments or block still raises LocalJumpError
:
3.tap #=> LocalJumpError: no block given
This also makes the existing shorthand even shorter:
object.tap { |o| o.example }
# vs
object.tap(&:example)
# vs
object.tap(:example)
Pull request: https://github.com/ruby/ruby/pull/2050
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0