Evan Light<p>I *LOVE* this resource (<a href="https://workingwithruby.com/wwrt/" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="">workingwithruby.com/wwrt/</span><span class="invisible"></span></a>) on threading in Ruby.</p><p>However, I find the suggestion to monkey patch Enumerable here (<a href="https://workingwithruby.com/wwrt/low_level_api/" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">workingwithruby.com/wwrt/low_l</span><span class="invisible">evel_api/</span></a>) evokes anxiety.</p><p>It suggests something like this:</p><p>module Enumerable<br> def concurrent_each<br> # impl<br> end<br>end</p><p>We Rubyists *LOVE* implicit over explicit relationships. We tend to think of this as convention over configuration. Thanks, DHH.</p><p>Yet this doesn't scale well.</p><p>For apps/gems of any significant complication, the accumulation of implicitness results in cognitive overload.</p><p>What if someone *else* gets the idea to add a concurrent_each to Enumerable. That is, Enumerable, as a built-in, is akin to a global namespace.</p><p>Instead, I recommend something more like a vaguely Java-esque approach (bear with me!) of:</p><p>class ConcurrentEach<br> def self.using(enumerable, &block)<br> # use the impl supplied in the example linked above<br> end<br>end</p><p>Using this would look like:</p><p>ConcurrentEach.using(files).each { ... }</p><p>This way, we're composing instead of monkey patching or mixing in.</p><p>Try to avoid modifying code you don't own.</p><p>Or, as I've heard, second-hand, of Matz saying to a friend of mine, "Don't hurt Ruby!" 😂</p><p><a href="https://tenforward.social/tags/Ruby" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>Ruby</span></a> <a href="https://tenforward.social/tags/monkeypatching" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>monkeypatching</span></a> <a href="https://tenforward.social/tags/composition" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>composition</span></a></p>