array_proc extends Ruby's Array class with a to_proc method, allowing you to call multiple methods on each element of an enumerable using the & shorthand syntax.
objects.map(&[:method_1, :method_2])
# is equivalent to the more verbose
objects.map { |element| [element.method_1, element.method_2] }Examining properties of numbers
[0, 5].map(&[:zero?, :even?])
# => [[true, true], [false, false]]Similar to its counterpart, string_proc, I recommend caution using this in production code. It's non-idiomatic Ruby and may cause more confusion than convenience. However, it can be a valuable tool for exploring and debugging objects in a REPL. For that reason, I often include it in my Gemfile with require: false ensuring that it won't be unintentionally used in code without explicitly requiring it via require 'array_proc'.
This is one of the first small gems I published, as it provides functionality that I find useful across multiple projects. By packaging it as a gem, I can avoid duplicating the code and reduce the need for repetitive testing in each project.
Include it in your project's Gemfile:
gem 'array_proc'