tapgives selfthe block passed to it and returns selfunchanged. I often wish there was a version tapthat returned the return value of the block, not self. For example:
[1,2].inject(:+).tap {|x| x * 3}
Is there a built-in method that will do this?
A typical solution - create a temporary local var to store the output [1,2].inject(:+)and multiply it by 3 - it seems kludgy.
Jonah source
share