[Ruby on Rails] The pluck Method is Convenient for Creating Single-Column Arrays

Tadashi Shigeoka ·  Fri, February 8, 2013

The pluck method, a new feature added in Ruby on Rails 3.2, is very convenient.

pluck (ActiveRecord::Calculations) - APIdock

Instead of creating a single-column array with map like this:

blog_titles = Blog.all.map(&:title)

With the pluck method, you can write it like this:

blog_titles = Blog.pluck(:title)

Moreover, it has better performance, so there’s no reason not to use pluck.

The Amazing Performance of the pluck Method Introduced in Rails 3.2 - (゚∀゚)o彡 sasata299’s blog

_人人人人人人人人人_ > pluck ステキ! <  ̄Y^Y^Y^Y^Y^Y^Y^Y ̄

#318 Upgrading to Rails 3.2 - RailsCasts

That’s all from the Gemba.