DEV Community

Discussion on: ruby methods - #tap and #then

Collapse
 
djuber profile image
Daniel Uber

These are great examples! The "dependent actions" tap scenario is the one I internalized the easiest - if you're assigning a value to a variable only to take intermediate actions before returning it (like your example) it's a natural refactoring.

I was totally unaware of Object#then until now, and will think about how to use that, too.

Collapse
 
anakbns profile image
Ana Nunes da Silva

Thank you for the feedback, Daniel. then is a recent discovery for me, too. Interestingly, it has been around since ruby 2.5 but with a different name - yield_self. Not long after, in ruby 2.6, the alias then was introduced. Apparently, yield_self was not a consensual name. I find this thread on the community discussing the method name really interesting.