Project

General

Profile

Feature #15419

Updated by shuber (Sean Huber) almost 6 years ago

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`: LocalJumpError 

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

 --- 

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

Back