Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created June 29, 2019 08:57
Show Gist options
  • Save mahemoff/fde4c30ad9fb3036a348d0560722b395 to your computer and use it in GitHub Desktop.
Save mahemoff/fde4c30ad9fb3036a348d0560722b395 to your computer and use it in GitHub Desktop.
Extending Array with Parallel gem
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) }
}
}
}
@mahemoff
Copy link
Author

Now we can call [1,2,3].each_in_parallel { |i| puts i }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment