I think this method I've just used it once in my life xD. I tend to forget about it. Its usage reminds me of the typical case of new array, fill array, return array which can be solved with map.
Without Array#map
ary=[]something.each{|thing|ary<<thing*2}ary
With Array#map
something.map{|thing|thing*2}
Thanks for sharing, now I have a good example for this kind of situation and how to solve it with Object#tap 😁
I think this method I've just used it once in my life xD. I tend to forget about it. Its usage reminds me of the typical case of new array, fill array, return array which can be solved with map.
Without
Array#map
With
Array#map
Thanks for sharing, now I have a good example for this kind of situation and how to solve it with
Object#tap
😁You got it!
Yeah, it's overkill but you can do something like this for the first example w/ tap:
This will return the array which is great in some cases.