Created
June 29, 2019 08:57
-
-
Save mahemoff/fde4c30ad9fb3036a348d0560722b395 to your computer and use it in GitHub Desktop.
Extending Array with Parallel gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
%w(each map each_with_index map_with_index flat_map any? all?).each { |meth| | |
define_method("#{meth}_in_parallel") { |&block| | |
Parallel.send(meth, self) { |item| block.call(item) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now we can call
[1,2,3].each_in_parallel { |i| puts i }