Reason #99 •
April 9th, 2026
ActiveSupport: Enumerable#pluck
When we have an enumerable full of hashes or hash-like values, pluck is a lovely shortcut for extracting one or more keys.
Ruby
repos = [
{ "name" => "ruby", "stars" => 225_000 },
{ "name" => "rails", "stars" => 57_000 }
]
repos.pluck("name")
# => ["ruby", "rails"]
repos.pluck("name", "stars")
# => [["ruby", 225000], ["rails", 57000]]
JavaScript
const repos = [
{ name: "ruby", stars: 225000 },
{ name: "rails", stars: 57000 }
];
repos.map((repo) => repo.name);
// => ["ruby", "rails"]
repos.map((repo) => [repo.name, repo.stars]);
// => [["ruby", 225000], ["rails", 57000]]
Pluck can also be used as a drop-in replacement for map(&:method_name), but since it also works through [], applying it to arrays of hashes is where it really shines.
History
Enumerable#pluck was added to ActiveSupport in Rails 5.0.0, released in 2016.
This expanded on the already existing pluck method in Active Record, released a few years prior, which fetches specific columns from the database.